【发布时间】:2014-08-04 21:47:40
【问题描述】:
我们有php代码:
define('myaesKey', 'znwoq8fq0jf2qjve8laper9f'); // 192 bits and 25 ch.
function encode($CodeTo) {
$Type = 'rijndael-128';
$Mode = 'ecb';
$IV = "1234567890123450";
$Object = mcrypt_module_open($Type, '', $Mode, '');
mcrypt_generic_init($Object , myaesKey, $IV);
$Enc2Code = mcrypt_generic($Object , $CodeTo);
mcrypt_generic_deinit($Object);
mcrypt_module_close($Object);
return bin2hex($secEncCode);
}
$CodeTo 的长度是 5,CodeTo 是英文字母的可读符号,函数发送类似这样的东西 1e49651ba23801907e1d67c5a7c18e06 aefdc02bbcb8ed8e8209a935aa62be53
我尝试通过 diff 解码。方法,其中之一:
const
KeySize = 24; // 32 bytes = 256 bits 24 - 192
BlockSize = 16; // 16 bytes = 128 bits
function Decrypt(AText:AnsiString):String;
var
Cipher : TDCP_rijndael; i:Integer;
Data, Key, IV,NewStr : ansistring;
begin
// Pad Key and IV with zeros as appropriate
Key := PadWithZeros(ansistring('znwoq8fq0jf2qjve8laper9f'),KeySize);
IV := PadWithZeros(ansistring('1234567890123450'),BlockSize);
// Decode the Base64 encoded string
NewStr:='';
for i:=1 to (Length(AText) div 2) do
NewStr:=NewStr+chr(byte(StrToInt('$'+Copy(AText,(i-1)*2+1,2))));
Data := NewStr;
// Create the cipher and initialise according to the key length
Cipher := TDCP_rijndael.Create(nil);
if Length(ansistring('znwoq8fq0jf2qjve8laper9f')) <= 16 then
Cipher.Init(Key[1],128,@IV[1])
else if Length(ansistring('znwoq8fq0jf2qjve8laper9f')) <= 24 then
Cipher.Init(Key[1],192,@IV[1])
else
Cipher.Init(Key[1],256,@IV[1]);
// Decrypt the data
// Cipher.DecryptCBC(Data[1],Data[1],Length(Data));
Cipher.DecryptECB(Data[1],Data[1]);
// Free the cipher and clear sensitive information
Cipher.Free;
FillChar(Key[1],Length(Key),0);
// Display the result
result:= Data;
end;
但是解码出来的文字是错误的
6d309aab9887deed8da964cca8818eb4 µ€ц‰ъиTDHQ ЮB№еП
为什么? 有人可以帮忙吗? http://www.tools4noobs.com/online_tools/decrypt/ withot IV 很容易解码...
【问题讨论】:
-
你必须注意两边都使用相同的编码
-
抱歉,已编辑。两种方式都不成功(
-
AFAIK PHP 使用 UTF8 编码的字符串。因此,您使用 UTF8 密码对一些 UTF8 字符串进行编码,并且您想使用 ANSI 密码对其进行解码……这只是编码问题,没有别的
-
Utf-8 没有帮助。代码你可以在这里看到gyazo.com/d28de0a5e36f903790fb76ee6d0dfa28.png
标签: php delphi encryption delphi-xe2 rijndael