我是这种加密和解密技术的新手。
我正在使用 Clickbank即时通知系统完成一项任务。我从 Clickbank 获取加密值,我想解密通知。我的问题与这个线程非常相似,但它对我不起作用。它抛出以下错误:
指定的初始化向量 (IV) 与此算法的块大小不匹配。
下面是我的解密代码。
protected void Page_Load(object sender, EventArgs e)
{
//Sample response
string sContent = "{\"notification\":\"18XR9s5fwkbhvfriqYS6jDJERf++jshcTDQX4NuUoUHtS+YzfMCNiEvmIVNxkbT5My2xWLFPB9mb\nEjwpHd3A6b9WJDYiXc0nufTxhXDAL1JzyYryEZAq7Bogj7mHjxUfFhc419wDmQteoSEz4H0IsKha\nIoxSfA5znd6WZKCSY9Dxx0wbZ8jLNL8SOYxi7pbFdKgMgKULKEh4EPKaWAvhE5UjWtzuHvMX37NI\nOvApkBoYEDE2mrde/SjLigE38X2wsGB4M6pYVkfzEE6rbYfVNxadkNHmri1xlaa+Grudy6vt6wzq\nPUfroEb6uRlxj2e6dmKZE4kynJFmRosMJ4ZRC+sYW+DyvkbdSY2dl1ZMNPhP+yhcMkbU8HQKUipw\nd7FUpb6utfiDB8YL5z7pJMnjHP01PsIvG+eSj0Lfj1gmbtVJt6TOJ4BCZxZdfdPRlJtPdOUiMRRk\nQ3Wn5g9VuvzNYg2ostZ+/HE778M6lZ264KbpMZSqEj4cTPCGFFNt7VCz9fXVoDLa7oI7KGY6rgxb\nBLWXdX058RSd0gSzC8otkCx9b6p8FZ5XxAX4qbU814batcbxw3V3GGVf97VLSVysdrHc+PEFdocl\nqaRarCHG5e2ZpEgQLoCtRhA99qkuS9Uc9+Hm1KT4kD2HIrPSclJWzUMoKuAG4n95EG0Q5ca0WZQx\naLNhdPyJmSLNwjV/SNPxYdyy81ENZtLbwJOYENCnpd41z73HF91/R1hrxQ0rCZsb6BBRGUeowEzE\nSKPSbWjDCQ6hLZTjObsOt6eTAmn8TrzjyqdwUfxHhLEtIQIOr4gPXxXqwGHYcNkRFezkwMScl2Hr\nmJ+Zm1xCqs9+fOOiO6TtZYKS+9Dl/JevMfGdbcPw8/5F7+ZVAkCcDS8OGaVv\",\"iv\":\"NDVEM0M4ODZGMzE4OTVENA==\"}";
using (var reader = new StreamReader(Request.InputStream))
{
//Using below two lines for live testing
//JavaScriptSerializer js = new JavaScriptSerializer();
//sContent = reader.ReadToEnd();
JObject jObject = JObject.Parse(sContent);
JToken notification = jObject["notification"];
JToken i = jObject["iv"];
using (StreamWriter _testData = new StreamWriter(Server.MapPath("~/data.txt"), true))
{
_testData.WriteLine("=======================Notification"); // Write the file.
_testData.WriteLine(notification.ToString());
_testData.WriteLine("=======================IV"); // Write the file.
_testData.WriteLine(i.ToString());
string n = notification.ToString();
string v = i.ToString();
string sk = "MY SECRET KEY";
byte[] key = Encoding.UTF8.GetBytes(sk);
byte[] iv = Encoding.UTF8.GetBytes(v);
try
{
using (var rijndaelManaged =
new RijndaelManaged { Key = key, IV = iv, Mode = CipherMode.CBC })
using (var memoryStream =
new MemoryStream(Convert.FromBase64String(n)))
using (var cryptoStream =
new CryptoStream(memoryStream,
rijndaelManaged.CreateDecryptor(key, iv),
CryptoStreamMode.Read))
{
var dString = new StreamReader(cryptoStream).ReadToEnd();
}
}
catch (CryptographicException ex)
{
Console.WriteLine("A Cryptographic error occurred: {0}", ex.Message);
}
}
}
}
请让我知道我错在哪里?
谢谢