开发者

encrypt array in php

Does anyone know do there have any way that I can encrypt the array in php??

for example:

$arr_value = array("1","2","3","4");

any way that I can encrypt $arr_value, al开发者_StackOverflow社区so decrypt it later ini php?


First, see this please.

You can encrypt/decrypt something like this:

$arr_value = array("1","2","3","4");

function encrypt($text)
{
   return base64_encode($text);
}

function decrypt($text)
{
   return base64_decode($text);
}

Now to encrypt:

$encrypted = array_map("encrypt", $arr_value);
echo '<pre>';
print_r($encrypted);

And to decrypt:

$decrypted = array_map("decrypt", $arr_value);
echo '<pre>';
print_r($decrypted);

.

Note:

It is worth having a look at a better way of encryption library:

The mcrypt library.


if you encrypt/decrypt string then use .

$str_value = $arr_value.join(",");

encrypt/decrypt $str_value

$arr_value=$str_value.split(",")


You might enjoy a look at mcrypt. I'm not sure where you're storing the encrypted values, or what cipher you want to use. mcrypt should let you accomplish whatever you need.

Examples are here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜