I have this Python decryption function which I am trying to convert to Delphi.
It uses AES CFB mode:
def aes_decrypt(data,key,iv):
ctx = AES.new(key, AES.MODE_CFB, iv=iv, segment_size=128)
decrypted = ctx.decrypt(data)
return decrypted
I am using Dcpcrypt in Delphi 7. // key is Md5 hash (this key/IV is just example not exact)
const
Key = 'c143vvssaaea933f04e956a3ff5vb562';
iv = 'r4022f4577726207fy0etf4fate2gd44';
function aes_decrypt(Data: TBytes; key,iv: string): TBytes;
var
Cipher: TDCP_rijndael;
InStrm, OutStrm: TMemoryStream;
begin
InStrm := TMemoryStream.Create;
OutStrm := TMemoryStream.Create;
InStrm.Write(Data[0], Length(Data));
Cipher := TDCP_rijndael.Create(nil);
Cipher.BlockSize:=128;
Cipher.CipherMode:=cmCFB8bit;
Cipher.Init(Key, 128, @IV);
Cipher.DecryptStream(InStrm, OutStrm, OutStrm.Size);
SetLength(Result, Integer(OutStrm.size));
OutStrm.Seek(0, 0);
OutStrm.Read(Result[0], Length(Result));
OutStrm.SaveToFile('decbuf.bin');
InStrm.Free;
OutStrm.Free;
Cipher.Free;
end;
I am getting incorrect output with the Delphi code; the Python function is returning the expected output.
The segment_size
segment_size (integer) – (Only MODE_CFB).The number of bits the plaintext and ciphertext are segmented in. It must be a multiple of 8. If not specified, it will be assumed to be 8.
does this apply in Delphi Dcpcrypt ?