0

我认为这将非常简单,但我在让我的 AES 加密函数返回一个十六进制字符串时遇到了问题。当我将它转换为 Base64 时,我可以让它工作,但我无法获得具有十六进制值的字符串。这是我的代码。任何帮助,将不胜感激。

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
4

1 回答 1

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 中格式化十六进制字符串,但这至少应该是一个开始。

于 2014-03-16T07:59:31.653 回答