crypto-js 3DES 加密解密

// 3des解密
export const decrypt = (params: any) => {
  const pubKey = localStorage.getItem(‘server_key‘);
  if (pubKey == null) {
    throw new Error(‘missing server pubKey‘);
  }
  const keyHex = CryptoJS.enc.Utf8.parse(HashHelper.Md5(pubKey));
  const decrypted = CryptoJS.TripleDES.decrypt(decodeURIComponent(params), keyHex, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return decrypted.toString(CryptoJS.enc.Utf8);
};
// 3des加密
export const encrypt = (params: any) => {
  const pubKey = localStorage.getItem(‘server_key‘);
  if (pubKey == null) {
    throw new Error(‘missing server pubKey‘);
  }
  const keyHex = CryptoJS.enc.Utf8.parse(pubKey);
  const encrypted = CryptoJS.TripleDES.encrypt(params, keyHex, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
};

 

crypto-js 3DES 加密解密

[db:回答]

以上是crypto-js 3DES 加密解密的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>