[bug fix] encrypt raw data without utf-8 encoding

This commit is contained in:
x 2025-06-10 16:09:49 +08:00
parent c57556f49f
commit c32b7713c0

View file

@ -72,9 +72,8 @@ class RSAEncrypt extends Operation {
// Load public key // Load public key
const pubKey = forge.pki.publicKeyFromPem(pemKey); const pubKey = forge.pki.publicKeyFromPem(pemKey);
// https://github.com/digitalbazaar/forge/issues/465#issuecomment-271097600 // https://github.com/digitalbazaar/forge/issues/465#issuecomment-271097600
const plaintextBytes = forge.util.encodeUtf8(input);
// Encrypt message // Encrypt message
const eMsg = pubKey.encrypt(plaintextBytes, scheme, {md: MD_ALGORITHMS[md].create()}); const eMsg = pubKey.encrypt(input, scheme, {md: MD_ALGORITHMS[md].create()});
return eMsg; return eMsg;
} catch (err) { } catch (err) {
if (err.message === "RSAES-OAEP input message length is too long.") { if (err.message === "RSAES-OAEP input message length is too long.") {