Encryption / Decryption problem -
09-20-2007
, 08:46 AM
Hello!
When I decrypt my messages there is almost always some text missing at
the end. Also very short messages get decrypted to empty strings.
Example code in Delphi.net
-----
function TWebservice1.EncryptValue(Value: string): ByteArray;
var
Cipher : RijndaelManaged;
transform : ICryptoTransform;
begin
try
Cipher := RijndaelManaged.Create;
Cipher.KeySize := 256;
Cipher.key := convert.FromBase64String(LogoKrypteringsStreng);
Cipher.IV := Convert.FromBase64String(LogoKrypteringsVektor);
Cipher.Padding := PaddingMode.PKCS7;
transform := cipher.CreateEncryptor;
result :=
transform.TransformFinalBlock(Encoding.Unicode.Get Bytes(Value),
0,value.Length);
except
on e : Exception do begin
SkrivLog(e.Message);
raise;
end;
end;
end;
function TWebservice1.DecryptValue(KrypteretValue: ByteArray): string;
var
Cipher : RijndaelManaged;
transform : ICryptoTransform;
begin
try
Cipher := RijndaelManaged.Create;
Cipher.KeySize := 256;
Cipher.key := convert.FromBase64String(LogoKrypteringsStreng);
Cipher.IV := convert.FromBase64String(LogoKrypteringsVektor);
Cipher.Padding := PaddingMode.PKCS7;
transform := cipher.CreateDecryptor;
result :=
Encoding.Unicode.GetString(transform.TransformFina lBlock(KrypteretValue,
0,Length(KrypteretValue)));
except
on e : Exception do begin
SkrivLog(e.Message);
raise;
end;
end;
end; |