gpt4 book ai didi

php - Aes|Rijndael-128 在 Delphi XE2 中进行哈希文本解码

转载 作者:行者123 更新时间:2023-12-01 22:33:39 25 4
gpt4 key购买 nike

我们有 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是英文字母的可读符号,函数发送这样的东西1e49651ba23801907e1d67c5a7c18e06aefdc02bbcb8ed8e8209a935aa62be53

我尝试通过 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/ 轻松解码,无需 IV ...

最佳答案

尝试使用这个

function AESDecrypt(AData, AKey: String): string;
var
KeyByte,Data,Dest:TBytes;
KeyBlock:integer;
Cipher:TDCP_rijndael;

begin
KeyByte:=TEncoding.UTF8.GetBytes(AKey);
while (Length(KeyByte) mod 16 <> 0) do begin
SetLength(KeyByte,Length(KeyByte)+1);
KeyByte[Length(KeyByte)-1]:=0;
end;

SetLength(Data,Length(AData) div 2);
SetLEngth(Dest,Length(AData) div 2);

Data:=GetBytesFromHex(AData);

Cipher:= TDCP_rijndael.Create(nil);

KeyBlock:=192; //by PHP code comment

Cipher.Init(KeyByte[0],KeyBlock,nil); //for ECB method IV is optional

try
for i := 1 to (Length(AData) div 16) do
begin
Cipher.DecryptECB(Data[(i-1)*16],Dest[(i-1)*16]);
end;
finally
Cipher.Burn;
end;
AData:=TEncoding.UTF8.GetString(Dest);
Result:=AData;
end;

关于php - Aes|Rijndael-128 在 Delphi XE2 中进行哈希文本解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21139935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com