0
我想这将是非常简单的,但我有一个问题,让我的AES加密函数返回一个十六进制字符串。当我将它转换为Base64时,我可以使它工作,但我无法使用十六进制值获取字符串。这是我的代码。任何帮助,将不胜感激。AES加密输出十六进制vb.net
Dim AES_ENCRYPTION As New System.Security.Cryptography.RijndaelManaged
Dim CODE_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encrypted As String = ""
Try
Dim hash(31) As Byte
Dim temp As Byte() = CODE_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
Array.Copy(temp, 0, hash, 0, 16)
Array.Copy(temp, 0, hash, 15, 16)
AES_ENCRYPTION.Key = hash
AES_ENCRYPTION.Mode = CipherMode.ECB
Dim AES_ENCRYPTOR As System.Security.Cryptography.ICryptoTransform = AES_ENCRYPTION.CreateEncryptor
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
encrypted = (Conversion.Hex(AES_ENCRYPTOR.TransformFinalBlock(Buffer, 0, Buffer.Length)))
Catch ex As Exception
End Try
Return encrypted
从[你如何将字节数组转换为十六进制字符串,反之亦然?](http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-十六进制字符串,反之亦然)并将其转换为vb.net – CodesInChaos
我还想指出,您的加密方法很弱(ECB,没有MAC,没有IV)以及您对待密钥无意义的方式。您不使用适当的盐渍和慢密码哈希,如PBKDF2。我不知道你奇怪的复制应该达到什么目的。您无声地破坏ASCII范围之外的Unicode数据。 – CodesInChaos
这就是为什么我来到StackOverFlow。这不是项目或生产代码。这是玩的东西。感谢您的链接。 –