JS加解密函数CryptoJS.enc.Hex.parse(word)在foxtable中,用什么函数或代码替代呢?
要实现加解密功能的JS代码如下:
//aes加密
function encrypt(word) {
var key = CryptoJS.enc.Utf8.parse("1234567890000000"); //16位
var iv = CryptoJS.enc.Utf8.parse("1234567890000000");
var encrypted = '';
if (typeof(word) == 'string') {
var srcs = CryptoJS.enc.Utf8.parse(word);
encrypted = CryptoJS.AES.encrypt(srcs, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
} else if (typeof(word) == 'object') {//对象格式的转成json字符串
data = JSON.stringify(word);
var srcs = CryptoJS.enc.Utf8.parse(data);
encrypted = CryptoJS.AES.encrypt(srcs, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
})
}
return encrypted.ciphertext.toString();
}
// aes解密
function decrypt(word) {
var key = CryptoJS.enc.Utf8.parse("1234567890000000");
var iv = CryptoJS.enc.Utf8.parse("1234567890000000");
var encryptedHexStr = CryptoJS.enc.Hex.parse(word);
var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
var decrypt = CryptoJS.AES.decrypt(srcs, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
return decryptedStr.toString();
}
待完善代码:
system.security.cryptography 命名空间SSC
全局代码:
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