我认为这将非常简单,但我的问题是让我的AES加密功能返回一个十六进制字符串。当我将它转换为Base64时,我可以使它工作但我无法获得带有Hex值的String。这是我的代码。任何帮助将不胜感激。
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
答案 0 :(得分:0)
我已经尝试了你的榜样,我也没有得到任何东西。
所以我尝试了而不是encrypted = (Conversion.Hex(AES_ENCRYPTOR.TransformFinalBlock(Buffer, 0, Buffer.Length)))
,我使用循环将每个字节转换为十六进制等效值,并将其连接到encrypted
。
Dim encrypted_byte() As Byte = AES_ENCRYPTOR.TransformFinalBlock(Buffer, 0, Buffer.Length)
For i As Integer = 0 To encrypted_byte.Length - 1
encrypted = encrypted & Hex(encrypted_byte(i)).ToUpper
Next
我不确定你是如何在Java中格式化十六进制字符串的,但这应该至少是一个开始。