首页 > Web开发 > 详细

crypto-js 3DES 加密解密

时间:2021-09-16 17:04:59      阅读:30      评论:0      收藏:0      [点我收藏+]
// 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 加密解密

原文:https://www.cnblogs.com/huangmin1992/p/15268524.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!