I have publicKey.cer
file with me and I want to encrypt some text using that certificate.
I need to use is RSA/ECB/OAEPWithSHA-256AndMGF1Padding
algorithm.
this answer here suggested that we can use below code to encrypt.
I am using node-forge npm package. as it was suggested in above linked answer. Which outdated. So latest library suggestion is also welcome as I couldn't find any other way thus far.
But I am unable to figure out how can I use publicKey
when I have .cer
file with me. How can I convert my .cer
file to this publicKey
below. Tried many googling but unable to get this.
var encrypted = publicKey.encrypt(bytes, 'RSA-OAEP', {
md: forge.md.sha256.create(),
mgf1: {
md: forge.md.sha256.create()
}
});