Answer the question
In order to leave comments, you need to log in
How to decrypt AES, a component of DCPcrypt?
When decrypting, (the keys and the source text are correct, they are decrypted in PHP), a different result is obtained.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DCPrijndael, DCPsha1, DCPsha256, DCPbase64, DCPcrypt2;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ekey,inData,outData,iv: array of byte;
DCP_rijndael1: TDCP_rijndael;
hashSha256: TDCP_sha256;
i: integer;
begin
Memo1.Text:= '';
SetLength(ekey,32);
ekey[0]:= 24;
ekey[1]:= 36;
ekey[2]:= 238;
ekey[3]:= 166;
ekey[4]:= 104;
ekey[5]:= 47;
ekey[6]:= 110;
ekey[7]:= 134;
ekey[8]:= 41;
ekey[9]:= 126;
ekey[10]:= 153;
ekey[11]:= 138;
ekey[12]:= 224;
ekey[13]:= 58;
ekey[14]:= 27;
ekey[15]:= 211;
ekey[16]:= 161;
ekey[17]:= 150;
ekey[18]:= 219;
ekey[19]:= 4;
ekey[20]:= 47;
ekey[21]:= 171;
ekey[22]:= 118;
ekey[23]:= 186;
ekey[24]:= 71;
ekey[25]:= 2;
ekey[26]:= 4;
ekey[27]:= 132;
ekey[28]:= 150;
ekey[29]:= 181;
ekey[30]:= 225;
ekey[31]:= 188;
SetLength(iv,32);
iv[0]:= 115;
iv[1]:= 177;
iv[2]:= 54;
iv[3]:= 205;
iv[4]:= 146;
iv[5]:= 241;
iv[6]:= 247;
iv[7]:= 167;
iv[8]:= 97;
iv[9]:= 216;
iv[10]:= 227;
iv[11]:= 121;
iv[12]:= 251;
iv[13]:= 9;
iv[14]:= 172;
iv[15]:= 108;
iv[16]:= 248;
iv[17]:= 153;
iv[18]:= 208;
iv[19]:= 11;
iv[20]:= 22;
iv[21]:= 0;
iv[22]:= 83;
iv[23]:= 25;
iv[24]:= 49;
iv[25]:= 71;
iv[26]:= 159;
iv[27]:= 3;
iv[28]:= 217;
iv[29]:= 95;
iv[30]:= 144;
iv[31]:= 164;
SetLength(inData,64);
inData[0]:= 21;
inData[1]:= 67;
inData[2]:= 30;
inData[3]:= 50;
inData[4]:= 51;
inData[5]:= 231;
inData[6]:= 73;
inData[7]:= 159;
inData[8]:= 142;
inData[9]:= 59;
inData[10]:= 140;
inData[11]:= 161;
inData[12]:= 40;
inData[13]:= 33;
inData[14]:= 93;
inData[15]:= 73;
inData[16]:= 47;
inData[17]:= 48;
inData[18]:= 129;
inData[19]:= 136;
inData[20]:= 183;
inData[21]:= 114;
inData[22]:= 28;
inData[23]:= 116;
inData[24]:= 221;
inData[25]:= 49;
inData[26]:= 83;
inData[27]:= 223;
inData[28]:= 134;
inData[29]:= 153;
inData[30]:= 85;
inData[31]:= 86;
inData[32]:= 74;
inData[33]:= 142;
inData[34]:= 149;
inData[35]:= 96;
inData[36]:= 124;
inData[37]:= 168;
inData[38]:= 232;
inData[39]:= 236;
inData[40]:= 245;
inData[41]:= 232;
inData[42]:= 219;
inData[43]:= 8;
inData[44]:= 217;
inData[45]:= 207;
inData[46]:= 12;
inData[47]:= 186;
inData[48]:= 65;
inData[49]:= 92;
inData[50]:= 145;
inData[51]:= 160;
inData[52]:= 134;
inData[53]:= 201;
inData[54]:= 244;
inData[55]:= 139;
inData[56]:= 169;
inData[57]:= 172;
inData[58]:= 185;
inData[59]:= 101;
inData[60]:= 185;
inData[61]:= 55;
inData[62]:= 140;
inData[63]:= 54;
SetLength(outData,1000);
for i:= 0 to 999 do outData[i]:= 0;
DCP_rijndael1:= TDCP_rijndael.Create(self);
DCP_rijndael1.Init(ekey,256,@iv[0]);//InitStr(AnsiString(key), TDCP_sha256);//Init(ekey2,256,@ivv[0]);//Init(ekey,256,nil);////InitStr(key,TDCP_sha256);
// DCP_rijndael1.InitStr(ansiString('kLpRNNDyNM8JrMX3'),TDCP_sha256);
DCP_rijndael1.SetIV(iv);
DCP_rijndael1.BlockSize:= Length(iv);
DCP_rijndael1.CipherMode:= cmCBC;
DCP_rijndael1.DecryptCBC(inData,outData[0],Length(inData));
DCP_rijndael1.Burn;
DCP_rijndael1.Free;
// out:= DCP_rijndael1.DecryptString(toDecrypt);
// DCP_rijndael1.EncryptCBC(toDecrypt,outdata[0],Length(toDecrypt));
Memo1.Text:= string(outdata); //исходной строчки мне не показало
end;
end.
<?php
ini_set("default_charset","cp1251");
$ekey = "";
$iv = "";
$encrypted = "";
$ekey = chr(24);
$ekey .= chr(36);
$ekey .= chr(238);
$ekey .= chr(166);
$ekey .= chr(104);
$ekey .= chr(47);
$ekey .= chr(110);
$ekey .= chr(134);
$ekey .= chr(41);
$ekey .= chr(126);
$ekey .= chr(153);
$ekey .= chr(138);
$ekey .= chr(224);
$ekey .= chr(58);
$ekey .= chr(27);
$ekey .= chr(211);
$ekey .= chr(161);
$ekey .= chr(150);
$ekey .= chr(219);
$ekey .= chr(4);
$ekey .= chr(47);
$ekey .= chr(171);
$ekey .= chr(118);
$ekey .= chr(186);
$ekey .= chr(71);
$ekey .= chr(2);
$ekey .= chr(4);
$ekey .= chr(132);
$ekey .= chr(150);
$ekey .= chr(181);
$ekey .= chr(225);
$ekey .= chr(188);
$iv = chr(115);
$iv .= chr(177);
$iv .= chr(54);
$iv .= chr(205);
$iv .= chr(146);
$iv .= chr(241);
$iv .= chr(247);
$iv .= chr(167);
$iv .= chr(97);
$iv .= chr(216);
$iv .= chr(227);
$iv .= chr(121);
$iv .= chr(251);
$iv .= chr(9);
$iv .= chr(172);
$iv .= chr(108);
$iv .= chr(248);
$iv .= chr(153);
$iv .= chr(208);
$iv .= chr(11);
$iv .= chr(22);
$iv .= chr(0);
$iv .= chr(83);
$iv .= chr(25);
$iv .= chr(49);
$iv .= chr(71);
$iv .= chr(159);
$iv .= chr(3);
$iv .= chr(217);
$iv .= chr(95);
$iv .= chr(144);
$iv .= chr(164);
$inData = chr(21);
$inData .= chr(67);
$inData .= chr(30);
$inData .= chr(50);
$inData .= chr(51);
$inData .= chr(231);
$inData .= chr(73);
$inData .= chr(159);
$inData .= chr(142);
$inData .= chr(59);
$inData .= chr(140);
$inData .= chr(161);
$inData .= chr(40);
$inData .= chr(33);
$inData .= chr(93);
$inData .= chr(73);
$inData .= chr(47);
$inData .= chr(48);
$inData .= chr(129);
$inData .= chr(136);
$inData .= chr(183);
$inData .= chr(114);
$inData .= chr(28);
$inData .= chr(116);
$inData .= chr(221);
$inData .= chr(49);
$inData .= chr(83);
$inData .= chr(223);
$inData .= chr(134);
$inData .= chr(153);
$inData .= chr(85);
$inData .= chr(86);
$inData .= chr(74);
$inData .= chr(142);
$inData .= chr(149);
$inData .= chr(96);
$inData .= chr(124);
$inData .= chr(168);
$inData .= chr(232);
$inData .= chr(236);
$inData .= chr(245);
$inData .= chr(232);
$inData .= chr(219);
$inData .= chr(8);
$inData .= chr(217);
$inData .= chr(207);
$inData .= chr(12);
$inData .= chr(186);
$inData .= chr(65);
$inData .= chr(92);
$inData .= chr(145);
$inData .= chr(160);
$inData .= chr(134);
$inData .= chr(201);
$inData .= chr(244);
$inData .= chr(139);
$inData .= chr(169);
$inData .= chr(172);
$inData .= chr(185);
$inData .= chr(101);
$inData .= chr(185);
$inData .= chr(55);
$inData .= chr(140);
$inData .= chr(54);
echo rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$ekey,$inData,MCRYPT_MODE_CBC,$iv),"\0\4");
Answer the question
In order to leave comments, you need to log in
Is it necessary to use d7? Why not a newer version? For example, the free version of RAD Studio 10.3.3 CE, where encryption comes out of the box.
Look at Chilkat, there are ready-made solutions.
procedure TFormMenu.Button1Click(Sender: TObject);
var
crypt: HCkCrypt2;
success: Boolean;
ivHex: PWideChar;
keyHex: PWideChar;
encStr: PWideChar;
begin
crypt := CkCrypt2_Create();
CkCrypt2_putCryptAlgorithm(crypt, 'rijndael');
CkCrypt2_putCipherMode(crypt, 'cbc');
CkCrypt2_putKeyLength(crypt, 256);
CkCrypt2_putPaddingScheme(crypt, 0);
CkCrypt2_putEncodingMode(crypt, 'base64'); // выбираешь какой формат выходящих данных тебе нужен, hex как пример
ivHex := '6b4c70524e4e44794e4d384a724d5833'; // твой ключ iv, как пример kLpRNNDyNM8JrMX3 в hex
CkCrypt2_SetEncodedIV(crypt, ivHex, 'hex');
keyHex := '6b4c70524e4e44794e4d384a724d5833'; // твой секретный ключ, как пример kLpRNNDyNM8JrMX3 в hex
CkCrypt2_SetEncodedKey(crypt, keyHex, 'hex');
Showmessage(CkCrypt2__encryptStringENC(crypt, PWideChar('test'))); // Result := CkCrypt2__decryptStringENC(crypt, PWideChar('test'));
CkCrypt2_Dispose(crypt);
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question