我需要将尽可能多的字符存储在具有 char 字符串的 cookie 上,以便以 AES 加密存储。
cookie 有大约 4kb 的内存。
所以我需要计算在 AES 中加密所有这些字符的 cookie 中可以存储多少字符。
要存储的字符是一个字母数字字符串。
编辑:我可以在明文和 Chipertext 中允许所有 UTF-8 字母数字字符
这是我的一段代码
<?php
$Pass = "132ksjcngpt04938idjsk39urtokg";
$Clear = "123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123456789012345678901234567890123456789o";
$crypted = fnEncrypt($Clear, $Pass);
echo "Encrypred: ".$crypted."<br></br>";
$newClear = fnDecrypt($crypted, $Pass);
echo "Decrypred: ".$newClear."<br></br>";
function fnEncrypt($sValue, $sSecretKey)
{
return trim(
base64_encode(
mcrypt_encrypt(
MCRYPT_RIJNDAEL_128,
$sSecretKey, $sValue,
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_128,
MCRYPT_MODE_ECB
),
MCRYPT_RAND)
)
)
);
}
function fnDecrypt($sValue, $sSecretKey)
{
return trim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_128,
$sSecretKey,
base64_decode($sValue),
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_128,
MCRYPT_MODE_ECB
),
MCRYPT_RAND
)
)
);
}
?>
我测试了,结果如下:
Encrypred: xINH9LnDsiwJjxrxAE7WYKTGBqw2tkKDx/04vryevRfkgKIqO0sRVurGW1Qu267CBuU9CwgS9YIXFs6zhM6y/limz3P8rST6phe5xP9zsw1tX42ngl7SgmK6apoVTjkXtxzY2XQtsuhBv6gPqBG1uoNqhU9QbhQXnbrqQUL7jG0UxGxqbAgb49atHjkTap4H55yzd4dJROlJ9G98rKe1znEU17XDUWjgDkebgG2puew804Sxh+seRMyV4MqmA4bt+uSKGASPQYONyHmY/3pz+yY0HFb/6GERHMOopJGGr17z9ZaQ7R6EeuGko1tiKYxfOX7Ep1hzJqGZ97TWtL+gyF/WaTpFedgLoKTLYe/CcGH3vmCyCngeGAdhVeqJ2bw2KUbJnvGXwiFI4ZKqS6U9Jf9Gzw/IlVMYIlCbGeml1EtinVN82aTw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gkhVvulw7zX5T7MH3N7kVRIawieTzq4aLXT/8cSDR/S5w7IsCY8a8QBO1mCkxgasNrZCg8f9OL68nr0X5ICiKjtLEVbqxltULtuuwgblPQsIEvWCFxbOs4TOsv5Yps9z/K0k+qYXucT/c7MNbV+Np4Je0oJiumqaFU45F7cc2Nl0LbLoQb+oD6gRtbqDaoVPUG4UF5266kFC+4xtFMRsamwIG+PWrR45E2qeB+ecs3eHSUTpSfRvfKyntc5xFNe1w1Fo4A5Hm4BtqbnsPNOEsYfrHkTMleDKpgOG7fcgwEO8b4hbdZM893s5T4W65w7kB3E9LFMARJATuxEONiJHm3YcAFDdl04v/hLNoA==
Decrypred: 123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123hryd{}ls.-''ksllasllallallallallal:{}::{}jdhhfn123456789012345678901234567890123456789o
chiperText 由 3040 个 utf-8 字符组成
加密最多 4056 个 utf-8 字符