“指定了无效的算法”;当使用带有OFB密码模式的AES(VB.NET)时

编程入门 行业动态 更新时间:2024-10-28 07:25:03
本文介绍了“指定了无效的算法”;当使用带有OFB密码模式的AES(VB.NET)时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have to use AES encryption with OFB cipher mode , I use VB.NET 4.5 ,windows 8 and the following code:

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)

有什么建议吗?

推荐答案

是的,它可以使用BouncyCastle来工作,如@Plutonix所述使用Nuget安装BouncyCastle之后的新代码是:

Yes it works using BouncyCastle as @Plutonix mentioned my new code after install BouncyCastle using Nuget is:

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

谢谢:)

更多推荐

“指定了无效的算法”;当使用带有OFB密码模式的AES(VB.NET)时

本文发布于:2023-11-09 19:24:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   密码   模式   OFB   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!