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
we have the below code for encrypting and decrypting data using cryptojs in our app. Because we are in a closed environment and therefor sometimes sometimes no verifiable ssl certificates we can't use cryptojs due to its limitation of only being available on secure connections.
Therefor we want to use jsrsasign as a replacement since we are already using it for signing and digest calculation.
But by now we have not been able to find a proper replacement of the cryptojs code.
passphrase is a simple 64 bytes random string generated by jsrsasign.KJUR.crypto.Util.getRandomHexOfNbytes(64).
asyncfunctionkeysFromPassphrase(salt: BufferSource,passphrase: string){constenc=newTextEncoder().encode(passphrase);constbaseKey=awaitwindow.crypto.subtle.importKey('raw',enc,'PBKDF2',false,['deriveBits']);constkeys=awaitwindow.crypto.subtle.deriveBits({name: 'PBKDF2',hash: 'SHA-512',
salt,iterations: 1e5,},baseKey,256/* key */+128/* iv */,);constiv=newUint8Array(keys.slice(32));constkey=awaitwindow.crypto.subtle.importKey('raw',newUint8Array(keys.slice(0,32)),{name: 'AES-CBC'},false,['decrypt','encrypt',]);return{ key, iv };}asyncfunctionencrypt(plaintext: string,passphrase: string): Promise<{encryptedData: string;salt: string}>{consttextEncoder=newTextEncoder();constsaltStr=jsrsasign.KJUR.crypto.Util.getRandomHexOfNbytes(64);constsalt=textEncoder.encode(saltStr);const{ key, iv }=awaitkeysFromPassphrase(salt,passphrase);constcipherText=(awaitwindow.crypto.subtle.encrypt({name: 'AES-CBC', iv },key,textEncoder.encode(plaintext),))asArrayBuffer;constencryptedData=btoa(newUint8Array(cipherText).reduce((data,byte)=>{returndata+String.fromCharCode(byte);},''),);return{ encryptedData,salt: saltStr};}asyncfunctiondecrypt(cipherText: string,passphrase: string,salt: string): Promise<string>{consttextEncoder=newTextEncoder();const{ key, iv }=awaitkeysFromPassphrase(textEncoder.encode(salt),passphrase);constdecryptedData=(awaitwindow.crypto.subtle.decrypt({name: 'AES-CBC', iv },key,Uint8Array.from(atob(cipherText),(c)=>c.charCodeAt(0)),))asArrayBuffer;consttextDecoder=newTextDecoder();returntextDecoder.decode(decryptedData);}
Can someone pleae help use?
We are currently using version 10.5.1 of jsrsasign.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
we have the below code for encrypting and decrypting data using cryptojs in our app. Because we are in a closed environment and therefor sometimes sometimes no verifiable ssl certificates we can't use cryptojs due to its limitation of only being available on secure connections.
Therefor we want to use jsrsasign as a replacement since we are already using it for signing and digest calculation.
But by now we have not been able to find a proper replacement of the cryptojs code.
passphrase
is a simple 64 bytes random string generated byjsrsasign.KJUR.crypto.Util.getRandomHexOfNbytes(64)
.Can someone pleae help use?
We are currently using version 10.5.1 of jsrsasign.
Beta Was this translation helpful? Give feedback.
All reactions