所以我一直在試圖用c#研究AES加密。雖然我有點困擾IV,但是我很難理解加密,我希望能從別人那裏得到更多的解釋讓我超越這堵牆。如何實現與加密郵件附加IV的AES
無論如何,我發現有關IV的一些信息,以及如何將它發送到我的Web服務(因爲這是我使用AES的主要目的)和加密的消息。
這裏是我發現
http://old.nabble.com/AES-decryption-with-different-IV-td31004365.html
它說,你可以傳遞到解密它的目標時,你的IV附加到郵件的文章。
這就是說,我的問題是,它們是否與用於加密消息的IV轉換的正常字符串有關?或者你是否將你的IV附加在字節中?
這是我的主要解密
public string DecryptString(string encryptedString, string key)
{
if (encryptedString == null || encryptedString.Length <= 0)
throw new ApplicationException("No string to decrypt.");
if (key == null || key.Length <= 0)
throw new ApplicationException("No key.");
byte[] cipherText = Convert.FromBase64String(encryptedString);
Rijndael aes = new RijndaelManaged();
aes.Key = StringToByte(key);
aes.IV = GetIV(cipherText);
ICryptoTransform decryptor = aes.CreateDecryptor();
throw new NotImplementedException();
}
我GetIV()是
static public byte[] GetIV(string cipherText)
{
// IV will be attached to the beginning of the encrypted String
// needs the length of the IV
int ivStringLength = 16;
string ivString = cipherText.Substring(0, ivStringLength);
byte[] ivByte = StringToByte(ivString);
return ivByte;
}
NOW的基礎上,我讀
看來,這個其他線程你從加密中得到你的IV,但它不會是第一個N字符但是前N個字節。所以這讓我感到困惑!
另一件事,不應該用IV來加密與密鑰的消息。在上一篇文章中,他/她是用KEY和IV加密它,然後再將IV附加到消息前,然後將其轉換爲字符串?
編輯:抱歉,我忘了說我是創建Web服務的人,這是我試圖實現的加密。
你不能只是發送IV任何地方和任何你覺得喜歡的方式,並期望Web服務知道在哪裏可以找到它。您必須以與web服務兼容的方式發送。向Web服務所有者詢問規範。 –
我是創建Web服務的人。這就是我想要實現的。我需要客戶端請求在消息上附加IV。但我試圖從我的最終解決方式來正確地加密和解密它。 – gdubs