js写一个加密方法 把一个int类型的变量加密 然后在c#中 进行解密
在JavaScript中,可以使用以下方法加密一个int类型的变量:
function encryptInt(value) {
// 以某个固定的密钥进行加密,这里使用的是"secretKey"
var secretKey = "secretKey";
// 将int类型的变量转换为字符串
var stringValue = value.toString();
// 逐个字符对应密钥进行异或操作
var encryptedValue = "";
for (var i = 0; i < stringValue.length; i++) {
var charCode = stringValue.charCodeAt(i) ^ secretKey.charCodeAt(i % secretKey.length);
encryptedValue += String.fromCharCode(charCode);
}
return encryptedValue;
}
var originalValue = 12345;
var encryptedValue = encryptInt(originalValue);
console.log(encryptedValue); // 输出加密后的值
然后,在C#中进行解密,可以使用以下方法:
using System;
public class Program
{
public static void Main()
{
// 加密后的值
var encryptedValue = "ÛÙÙÙÛØ";
// 以相同的密钥进行解密,这里密钥为"secretKey"
var secretKey = "secretKey";
// 逐个字符对应密钥进行异或操作
var decryptedValue = "";
for (int i = 0; i < encryptedValue.Length; i++)
{
var charCode = (int)encryptedValue[i] ^ (int)secretKey[i % secretKey.Length];
decryptedValue += (char)charCode;
}
// 将解密后的字符串转换为int类型的变量
var originalValue = int.Parse(decryptedValue);
Console.WriteLine(originalValue); // 输出解密后的值
}
}
在上述代码中,使用相同的密钥和加密方法,可以实现在C#中对加密后的int类型变量进行解密
原文地址: http://www.cveoy.top/t/topic/id24 著作权归作者所有。请勿转载和采集!