I want to decrypt an HTTP response which is base64 encoded. I've also already got the fPassword
and fSalt
, but the offset of the response and length of the string I can not confirm.
Now I've got an prompt:
CryptographicException: Length of the data to decrypt is invalid.
Does it mean the offset or length of the data is not correct? What is the meaning of this error?
The exception happened when FlushfinalBlock was executing by the prompt.
public static byte[] dd_1(string string_0)
{
byte[] buffer = Convert.FromBase64String(string_0);
AesManaged managed = new AesManaged();
Rfc2898DeriveBytes bytes = new Rfc2898DeriveBytes(fPassword, fSalt);
managed.BlockSize = managed.LegalBlockSizes[0].MaxSize;
managed.KeySize = managed.LegalKeySizes[0].MaxSize;
managed.Key = bytes.GetBytes(managed.KeySize / 8);
managed.IV = bytes.GetBytes(managed.BlockSize / 8);
ICryptoTransform transform = managed.CreateDecryptor();
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.Close();
return stream.ToArray();
}