Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
Public Class AESEncryption ' 使用 AES-128-CBC 模式,密钥长度需为16字节(128位) Private Shared key As Byte() = Encoding.UTF8.GetBytes("0123456789abcdef") ' 密钥示例,需与Java端一致 Private Shared iv As Byte() = Encoding.UTF8.GetBytes("1234567890abcdef") ' 初始化向量(IV)示例 ' 加密方法 Public Shared Function EncryptJWM(plainText As String) As String Using aesAlg As System.Security.Cryptography.Aes = System.Security.Cryptography.Aes.Create() aesAlg.Key = key aesAlg.IV = iv aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC aesAlg.Padding = System.Security.Cryptography.PaddingMode.PKCS7 Dim encryptor As System.Security.Cryptography.ICryptoTransform = aesAlg.CreateEncryptor() Dim plainBytes As Byte() = Encoding.UTF8.GetBytes(plainText) Using msEncrypt As New IO.MemoryStream() Using csEncrypt As New System.Security.Cryptography.CryptoStream(msEncrypt, encryptor, System.Security.Cryptography.CryptoStreamMode.Write) csEncrypt.Write(plainBytes, 0, plainBytes.Length) csEncrypt.FlushFinalBlock() End Using Return Convert.ToBase64String(msEncrypt.ToArray()) End Using End Using End Function ' 解密方法 Public Shared Function DecryptJWM(cipherText As String) As String Dim cipherBytes As Byte() = Convert.FromBase64String(cipherText) Using aesAlg As System.Security.Cryptography.Aes = System.Security.Cryptography.Aes.Create() aesAlg.Key = key aesAlg.IV = iv aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC aesAlg.Padding = System.Security.Cryptography.PaddingMode.PKCS7 Dim decryptor As System.Security.Cryptography.ICryptoTransform = aesAlg.CreateDecryptor() Using msDecrypt As New IO.MemoryStream(cipherBytes) Using csDecrypt As New System.Security.Cryptography.CryptoStream(msDecrypt, decryptor, System.Security.Cryptography.CryptoStreamMode.Read) Using srDecrypt As New IO.StreamReader(csDecrypt, Encoding.UTF8) Return srDecrypt.ReadToEnd() End Using End Using End Using End Using End Function End Class 这段代码在旧版本的foxtable中无法编译,会报错 有什么解决方法吗 |