1
我必須使用與OFB加密模式的AES加密時「指定了無效的算法」,我使用VB.NET 4.5,窗口8和下面的代碼:使用AES與OFB加密模式(VB.NET)
Public Function DoEncryption(ByVal KeyArray() As Byte, ByVal IVArray() As Byte, ByVal Buffer As String) As Byte()
Dim encrypted() As Byte
Using a As Aes = Aes.Create()
a.Mode = CipherMode.OFB
Dim encryptor As ICryptoTransform
encryptor = a.CreateEncryptor(KeyArray, IVArray)
' Create the streams used for encryption.
Using msEncrypt As New MemoryStream()
Using csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
Using swEncrypt As New StreamWriter(csEncrypt)
'Write all data to the stream.
swEncrypt.Write(Buffer)
End Using
encrypted = msEncrypt.ToArray()
End Using
End Using
End Using
Return encrypted
End Function
我在
swEncrypt.Write(Buffer)
任何建議「無效的算法指定」的錯誤?
OFB。檢查[AesManaged.Mode屬性](https://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged.mode(v = vs.110).aspx)底部的註釋: 「不支持CFB和OFB模式。」我不確定Aes類與AesManaged有多大不同,但支持它而不支持其他類型會很奇怪。你可能會看看BouncyCastle – Plutonix
非常感謝@Plutonix,我會嘗試從nuget的Bouncy Castle並給予反饋,奇怪的是當我嘗試使用CFB時,它可以正常工作:( –