公司业务代码
const Base64 = require('base-64') function xorEncrypt (str, key) { let result const list = [] for (let i = 0; i < str.length; i++) { const charCode = str.charCodeAt(i) ^ key.charCodeAt(i % key.length) list.push(String.fromCharCode(charCode)) } result = list.join('') return encodeURIComponent(Base64.encode(result)) } const encryptedText = xorEncrypt(info, API_KEY) console.log('加密后:', encryptedText)
加密算法
function xorEncrypt(str, key) { const result = []; for (let i = 0; i < str.length; i++) { const charCode = str.charCodeAt(i) ^ key.charCodeAt(i % key.length); result.push(String.fromCharCode(charCode)); } return result.join(''); } const plaintext = "Hello, world!"; const encryptionKey = "secret"; // 加密 const encryptedText = xorEncrypt(plaintext, encryptionKey); console.log("加密后:", encryptedText);// 解密 const decryptedText = xorEncrypt(encryptedText, API_KEY) console.log('解密后:', decryptedText)
标签:const,str,JavaScript,xorEncrypt,异或,result,key,加密 From: https://www.cnblogs.com/qt-fei/p/17606664.html