kjur / jsrsasign

The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES and JSON Web Signature/Token in pure JavaScript.
https://kjur.github.io/jsrsasign
Other
3.25k stars 646 forks source link

RSAOAEP256 is gone, howto en/decrypt async? #614

Closed celevra closed 5 months ago

celevra commented 6 months ago

Hi,

before of the removal of RSAOAEP256 we have en decrypted like this:

let pubKey = rs.KEYUTIL.getKey(pemPubKey);
var encrypted = rs.KJUR.crypto.Cipher.encrypt('this is a Test', pubKey, 'RSAOAEP256 ')

let privKey = rs.KEYUTIL.getKey(pemPrivKey,'xxx')
var decrypted = rs.KJUR.crypto.Cipher.decrypt(encrypted, privKey, 'RSAOAEP256 ')

console.log(decrypted)

how is it done in aes256-CB? we tried it like this:

function generateHexString(length) {
    var ret = "";
    while (ret.length < length) {
        ret += Math.random().toString(16).substring(2);
    }
    return ret.substring(0, length);
}

var iv = generateHexString(16);

let pubKey = rs.KEYUTIL.getKey(pemPubKey);
var encrypted = rs.KJUR.crypto.Cipher.encrypt('this is a Test', pubKey, 'aes256-CBC', {iv: iv})

let privKey = rs.KEYUTIL.getKey(pemPrivKey,'xxx')
var decrypted = rs.KJUR.crypto.Cipher.decrypt(encrypted, privKey, 'aes256-CBC', {iv: iv})

console.log(decrypted)

but it gives us the wrong result thank you in advance for your help

kjur commented 5 months ago
var encrypted = rs.KJUR.crypto.Cipher.encrypt('this is a Test', pubKey, 'aes256-CBC', {iv: iv})

For AES-256 encryption, key value shall be a hexadecimal string with 64 characters.

celevra commented 5 months ago

ok but how to encrypt this 64 char hexadecimal string async?

we wan't to use private/public keys

kjur commented 5 months ago

Here is an example:

let k = "f305c553ff811197110f6b84541687fe51ba922d4da508fc222316ba4f010a6c";
let iv = "3cb8611d0fb0931b370bf982ecf06300";
let encmsg = KJUR.crypto.Cipher.decrypt("616161", k, "aes256-CBC", { iv: iv })
celevra commented 5 months ago

ok and how do i encrypt the k and iv with a public cert?

celevra commented 5 months ago

i don't agree that this is closed. There seem no way to use async encryption/decryption with certificates (private/public) Key anymore

kjur commented 5 months ago

Please use WebCrypto API instead: https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API