Closed DNAlchemist closed 2 years ago
1st argument of Cipher.encrypt shall be a raw string not a hexadecimal string. Is this resolve your issue?
From CryptoJS.PBKDF2 I get bytes, not a string I can cast it to hexadecimal, base64, but not to string cause I getting "Malformed Utf Data" (via CryptoJS)
I also tried
const aesRawString = pmlib.rs.hextorstr(aesKeyHex)
const encryptedAes = pmlib.rs.hextob64(pmlib.rs.KJUR.crypto.Cipher.encrypt(aesRawString, publicKey, 'RSAOAEP'))
But still getting decryption error
I've checked Cipher.encrypt/decrypt.
var prv = rs.KEYUTIL.getKey(prvpem);
var pub = rs.KEYUTIL.getKey(pubpem);
var s1 = "\x01\x02\x03\x00\x01\x02\x03\x00";
var e1 = rs.KJUR.crypto.Cipher.encrypt(s1, pub, "RSAOAEP");
console.log("e1", e1);
var s2 = rs.KJUR.crypto.Cipher.decrypt(e1, prv, "RSAOAEP");
console.log("s2", s2);
console.log("s2hex", rs.rstrtohex(s2)); // -> "0102030001020300"
console.log("cmp", s1 === s2); // -> true
Then Cipher.decrypt/encrypt works properly. Sorry but it seems your CryptoJS string handling issue. Thank you.
I can't find how to encrypt bytes or hexadecimal (produced by CryptoJS) with RSAES-OAEP (SHA-256 ) encryption. But can't decrypt byte array on backend side (backend code is correct) I'm using postman-utils-lib and do something like that:
It's possible?