Const key As String ="XXXXXXXXXXXXXXXX"
Const iv As String = "XXXXXXXXXXXXXXXX"
Public Function AesEncrypt(ByVal toEncrypt As String) As String
Dim keyArray As Byte() = UTF8Encoding.UTF8.GetBytes(key)
Dim ivArray As Byte() = UTF8Encoding.UTF8.GetBytes(iv)
Dim toEncryptArray As Byte() = UTF8Encoding.UTF8.GetBytes(toEncrypt)
Dim rDel As SSC.RijndaelManaged = New SSC.RijndaelManaged()
rDel.Key = keyArray
rDel.IV = ivArray
rDel.Mode = SSC.CipherMode.CBC
rDel.Padding = SSC.PaddingMode.Zeros
Dim cTransform As SSC.ICryptoTransform = rDel.CreateEncryptor()
Dim resultArray As Byte() = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length)
Return Convert.ToBase64String(resultArray, 0, resultArray.Length)
End Function
Public Function AesDecrypt(ByVal toDecrypt As String) As String
Dim keyArray As Byte() = UTF8Encoding.UTF8.GetBytes(key)
Dim ivArray As Byte() = UTF8Encoding.UTF8.GetBytes(iv)
Dim toEncryptArray As Byte() = Convert.FromBase64String(toDecrypt)
Dim rDel As SSC.RijndaelManaged = New SSC.RijndaelManaged()
rDel.Key = keyArray
rDel.IV = ivArray
rDel.Mode = SSC.CipherMode.CBC
rDel.Padding = SSC.PaddingMode.Zeros
Dim cTransform As SSC.ICryptoTransform = rDel.CreateDecryptor()
Dim resultArray As Byte() = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length)
Return UTF8Encoding.UTF8.GetString(resultArray)
End Function
比如我有个加密密钥是:1234567890123456
加密后的值为:"SWG12MXQ8evvU1981R0DqnNRL3QqPAn3lT2yXPP6tAn1DW4nB8XUjF9bNgpHK0p/y9MOv2Q6zy03mxOssMBpQ9H+Rz0fMQsxok/AZSF4KqvPHZmHWm7oAq7GRFywwml2p9y0HYi+JLY+y/1a0Z1IQeOXbAHS3D331hwNS5BO2nmFeH/JeH4h9+yKSzKB7nhzv2K9ykdBOrzJrJ3NIJQ0+7+vlzQMrBgH4xK3vDPd+ij+8q89m/uo+57c7j46jyEcdVieNlEo0C2k7TanwWVNPCy5VO08z1OiixspdQ5hu9dsl0J78RxEd4+RkDtkQFvaBQGHoM3lqYcsurCRq3PlUw=="
我想在代码中调用,并传值给函数,怎么使用?