Вопрос

I am facing a strange problem, i am using aes encryption with cfb mode. It is going good, I had tested the encryption with fixed IV. But when i use a random IV the problem shows up. I am going in detail.

function Random16DigitsString: AnsiString;
var
  i: Integer; c0: byte;
begin
  Randomize;
  c0:=ord('0');
  SetLength(Result, 16);
  Result[1] := char(c0+Random(9)+1);
  for i:=2 to 16 do Result[i] := char(c0+Random(10));
end;   

The sample output of the above code is 8229343736510872

When i use this function in encryption phase its ok, but when i decrypt the file using the same key then the output is garbage. But when i hard code this key in encryption phase then the decryption successfully goes.

What i am missing. I am going with simple random number generator.

Это было полезно?

Решение

I was using AnsiString to store the Key for the Context. This was the real problem because in pascal AnsiString is not single byte. As @CodeInChaos focused on AnsiString, I checked it and found it. So i had replaced the

Key: AnsiString  

To

Key : Array [0..32] of Char;

and it successfully worked.

Thank you @CodeInChaos.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top