vb.net - "Invalid algorithm specified"在 OFB 密码模式下使用 AES (VB.NET)

标签 vb.net algorithm encryption aes

我必须使用 OFB 密码模式的 AES 加密,我使用 VB.NET 4.5、windows 8 和以下代码:

   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)

有什么建议吗?

最佳答案

是的,它可以使用 @Plutonix 提到的 BouncyCaSTLe 使用 Nuget 安装 BouncyCaSTLe 后我的新代码是:

Imports System.Security.Cryptography
Imports System.IO
Imports Org.BouncyCastle.Crypto
Imports Org.BouncyCastle.Security
Imports Org.BouncyCastle.Crypto.Parameters
Public Class EncryptionFunction
Public Function DoEncryption(ByVal KeyArray() As Byte, ByVal IVArray() As Byte, ByVal Buffer As Byte()) As Byte()

        Dim ae As New CipherKeyGenerator()
        ae.Init(New KeyGenerationParameters(New SecureRandom(), 256))
        Dim aesKeyParam As KeyParameter = ParameterUtilities.CreateKeyParameter("AES", KeyArray)
        Dim aesIVKeyParam As ParametersWithIV = New ParametersWithIV(aesKeyParam, IVArray)
        Dim cipher As IBufferedCipher = CipherUtilities.GetCipher("AES/OFB/NoPadding")
        cipher.Init(True, aesIVKeyParam)
        Dim encrypted() As Byte = cipher.DoFinal(Buffer)


        Return encrypted

    End Function
End Class

谢谢你:)

关于vb.net - "Invalid algorithm specified"在 OFB 密码模式下使用 AES (VB.NET),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30560523/

相关文章:

java - 如何在 PHP 中复制 Java 加密?

vb.net - 防止在类库中创建 app.config

python - 在python中实现LZ78压缩算法

json - vb.NET 将 JSON 列表反序列化为对象

c# - 解决条件填充难题的排列/算法

algorithm - 寻找最低的平均等级差异

java - 使用 JVM 属性禁用特定的弱密码并强制执行完美前向保密

encryption - 在键值存储中查找加密 key

vb.net - 访问事件窗口中的自定义任务 Pane - Visual Basic、VSTO

vb.net 填充多列 ListView