Open WangYihang opened 9 months ago
I had the same problem trying to make PKCS#7 encryption.
My solution was after loading the certificate loop through issuer fields, read it as ASCII and write it back as UTF-8 like that:
certificate.issuer.attributes.forEach(element => { element.value = Buffer.from(Buffer.from(element.value, 'ASCII')).toString('utf-8'); });
The problem with certificateFromPem() function is that it uses the obsolete method of reading base64 see:
var msg = { type: type, procType: null, contentDomain: null, dekInfo: null, headers: [], body: forge.util.decode64(match[3]) };
It is only a hotfix but I hope it will help.
Description
I found that
forge
has an inconsistent behaviour betweencrypto
when parsing a certificate, which has a chinese character in subject value.The
crypto
library is able to return the correct value, butforge
can not.The proof of concept code shows as follows.
Proof of Concept
Current output
Expected output
Environment