You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DES decryption got different results, in CryptoJS I got the correct result, in CryptoES I need to split the encrypted HEX string to get the correct result.
The text was updated successfully, but these errors were encountered:
trasherdk
changed the title
Example: TripleDes / Des encrypt & decrypt result are not same as crypto-js
Snippet: TripleDes / Des encrypt & decrypt result are not same as crypto-js
Apr 28, 2024
importCryptoESfrom"crypto-es";// No need to split string in CryptoJS// https://codepen.io/brownsugar/pres/OJjJPYY?editors=0012functiondecrypt(string,key){constchunkLength=string.length/2;conststrings=[string.slice(0,chunkLength),string.slice(chunkLength)];constvalues=strings.map((s)=>decryptDES(s,key));returnvalues.join("").replace(/\0/g,"");}functiondecryptDES(encrypted,keyString){constciphertext=CryptoES.enc.Hex.parse(encrypted);constkey=CryptoES.enc.Utf8.parse(keyString);constdecrypted=CryptoES.DES.decrypt({
ciphertext
},key,{mode: CryptoES.mode.ECB,padding: CryptoES.pad.NoPadding});returndecrypted.toString(CryptoES.enc.Utf8);}constdata=["1;8D709DF37DD0F75702B98B13B48CCAC989421B49","1;B6C052F5259BC340C489A1C391BFCB67AFDC7D1B","1;65CE64E708401E956DF015E0BB9BE238B22AC4DD","1;761F348ACE19C9C6B7EFAB062B737950C71C5B48","1;38ADD29F4F24AEDE6D45A35A46DD5BD36E1DE3EA","1;29810AD241B5293ABA4E04B79F7C9C960AD4D779","1;965909504145BFEF3B5FDB01FD0B086787B1CC48","1;1CFFF0630506B58C9254D3F0DB59561A8DFD37C7","1;717A70C67008B436A6EFA38C2182C8BCF04E3C53","1;1348011174AD38961DD969DAEF75D5920CC91403"];constresult=data.map((d)=>{const[,string]=d.split(";");constkeyLength=8;constkey=string.slice(0,keyLength);consthexString=string.slice(keyLength);returndecrypt(hexString,key);});console.log(result);
As title, seems crypto-es is unable to produce the same output in both encrypt and decrypt as crypto-js. The output seems incorrect.
Source: entronad#22 (comment)
Sample
DES decryption got different results, in CryptoJS I got the correct result, in CryptoES I need to split the encrypted HEX string to get the correct result.
With CryptoJS
https://codepen.io/brownsugar/pres/OJjJPYY?editors=0012
With CryptoES
https://codesandbox.io/s/cryptoes-des-decryption-zt4cs
Source: entronad#22 (comment)
The text was updated successfully, but these errors were encountered: