DES加密

参考地址:vue DES加密(超详细)_u014678583的博客-CSDN博客_des vue

在与后台传输数据过程中,我们要避免采用明文传输密码相关的数据

后台对于密码的处理暂时采用的是des加密,为了保持与原来数据的一致性,也采用这种方式

按照参考地址的方式实现了以后,发现加密的数据与后台发过来的不一致,

又参考了地址

前端vue项目中cryptoJS AES加密_天山小黎的博客-CSDN博客

修改了填充方式,后来干脆修改了加密方式,但是仍然是不一致的

通过查找在线的des加密工具,来检验

参考地址:在线DES加密解密 - 加密解密

通过检验发现,是我的与加密的以后不符合

然后在检索改在线工具的加密的js

http://www.txttool.com/api/des/encrypt_des.js

观察以后发现,我觉得可能是我加密的数据发生了变化,直接传递数据,发现与后台加密后的一致了

存在的问题是参考的例子中对原始数据转化为了JSON格式,但是后台并没有采用这种方式,为了维持一致性去掉

而且后台采用的是固定的key值,因为暂时不需要用到生成random 的函数来生成key值

http://www.txttool.com/api/des/encrypt_des.js 源码

function encrypt(){let text=document.getElementById('area_text').value;if(text){let key=CryptoJS.enc.Utf8.parse(document.getElementById('input_key').value);try{let encrypted=CryptoJS.DES.encrypt(text,key,buildConfig());let encode=document.getElementById('select_output_encode').value;let cipherText=encrypted.toString();if(encode==='HEX'){cipherText=CryptoJS.enc.Hex.stringify(CryptoJS.enc.Base64.parse(cipherText));}
document.getElementById('area_cipher_text').value=cipherText;}catch(e){alert(e)}}}
function decrypt(){let text=document.getElementById('area_cipher_text').value;if(text){let encode=document.getElementById('select_output_encode').value;let cipherText;if(encode==='Base64'){cipherText=CryptoJS.enc.Base64.parse(text)}else if(encode==='HEX'){cipherText=CryptoJS.enc.Hex.parse(text)}
let key=CryptoJS.enc.Utf8.parse(document.getElementById('input_key').value);try{let decrypted=CryptoJS.DES.decrypt({ciphertext:cipherText},key,buildConfig());document.getElementById('area_text').value=decrypted.toString(CryptoJS.enc.Utf8);}catch(e){alert(e)}}}
function buildConfig(){let mode=document.getElementById('select_mode').value;let pad=document.getElementById('select_pad').value;let conf={};switch(mode){case 'CBC':conf.mode=CryptoJS.mode.CBC;break;case 'CFB':conf.mode=CryptoJS.mode.CFB;break;case 'CTR':conf.mode=CryptoJS.mode.CTR;break;case 'OFB':conf.mode=CryptoJS.mode.OFB;break;case 'ECB':conf.mode=CryptoJS.mode.ECB;break;}
switch(pad){case 'Pkcs7':conf.padding=CryptoJS.pad.Pkcs7;break;case 'Iso97971':conf.padding=CryptoJS.pad.Iso97971;break;case 'AnsiX923':conf.padding=CryptoJS.pad.AnsiX923;break;case 'Iso10126':conf.padding=CryptoJS.pad.Iso10126;break;case 'ZeroPadding':conf.padding=CryptoJS.pad.ZeroPadding;break;case 'NoPadding':conf.padding=CryptoJS.pad.NoPadding;break;}
conf.iv=CryptoJS.enc.Utf8.parse(document.getElementById('input_iv').value);return conf}
function cleanup(){document.getElementById('area_text').value='';document.getElementById('area_cipher_text').value='';document.getElementById('input_key').value='';document.getElementById('input_iv').value='';}

解密的时候又参考了原来的地址,发现解密不出来,参考工具发现密文编码应该是base64,修改后可以解析出来原来的密码了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值