2
我似乎無法解決這個問題,我創建了我認爲是一個256位密鑰使用隨機發生器在GRC並與我的IV結合。我不斷收到以下錯誤:ASP.NET Rijndael加密錯誤 - 指定的密鑰不是這個算法的有效大小
指定的密鑰對於此算法不是有效的大小。
任何幫助感激地接受,這裏是我使用的加密/解密代碼:
Private Function Rijndael(ByVal sInput As String, ByVal bEncrypt As Boolean) As String
' Setup the Key and Initialization Vector.
Dim byteKey As Byte() = Encoding.UTF8.GetBytes("C3CA193570B26E5C3CBB50FD805A0E23BAFFABA135E82C41517EEDCB9B7C90AC")
Dim byteIV As Byte() = Encoding.UTF8.GetBytes("c+O2r)J~?L:$]u[2")
' Create an instance of the encyrption algorithm.
Dim _rijndael As New RijndaelManaged()
' Create an encryptor using our key and IV
Dim transform As ICryptoTransform
If bEncrypt Then
transform = _rijndael.CreateEncryptor(byteKey, byteIV)
Else
transform = _rijndael.CreateDecryptor(byteKey, byteIV)
End If
' Create the streams for input and output
Dim msOutput As New System.IO.MemoryStream()
Dim msInput As New CryptoStream(msOutput, transform, CryptoStreamMode.Write)
' Feed data into the crypto stream.
msInput.Write(Encoding.UTF8.GetBytes(sInput), 0, Encoding.UTF8.GetBytes(sInput).Length)
' Flush crypto stream.
msInput.FlushFinalBlock()
Return Convert.ToBase64String(msOutput.ToArray)
End Function
是否有框架方法將十六進制字符串轉換爲字節[]? – 2009-12-02 21:26:10
謝謝,這個排序 - 非常感謝。 – Chris 2009-12-02 21:32:27