Foxtable(狐表)用户栏目专家坐堂 → [求助]16进制字符串转换为字符数组用什么函数或代码处理?


  共有5784人关注过本帖树形打印复制链接

主题:[求助]16进制字符串转换为字符数组用什么函数或代码处理?

帅哥哟,离线,有人找我吗?
sxfeiliu
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:112 积分:1016 威望:0 精华:0 注册:2020/3/6 13:14:00
[求助]16进制字符串转换为字符数组用什么函数或代码处理?  发帖心情 Post By:2022/9/20 12:58:00 [显示全部帖子]

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


 回到顶部
帅哥哟,离线,有人找我吗?
sxfeiliu
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:112 积分:1016 威望:0 精华:0 注册:2020/3/6 13:14:00
  发帖心情 Post By:2022/9/20 13:47:00 [显示全部帖子]

JS中的解密代码:var encryptedHexStr = CryptoJS.enc.Hex.parse(word);
在foxtable中应转换为什么代码?
目前无法正确解密JS加密的数据。

 回到顶部
帅哥哟,离线,有人找我吗?
sxfeiliu
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:112 积分:1016 威望:0 精华:0 注册:2020/3/6 13:14:00
  发帖心情 Post By:2022/9/20 20:29:00 [显示全部帖子]

终于搞定了,感谢!

 回到顶部