I am trying to implement openpgpjs on my application because I need to encrypt a string using a public key (PGP). I tested this jsfiddle (https://jsfiddle.net/gu72bzm8/) which encrypts a string using a public key, it works very well. I even tested it with different keys and strings.
var message = "secret message";
const encryptMessage = async() => {
if(window.crypto.getRandomValues){
if(message != ""){
const publicKeyString = document.getElementById("pubkey").innerHTML;
var options = {
message: openpgp.message.fromText(message),
publicKeys: (await openpgp.key.readArmored(publicKeyString)).keys
};
openpgp.encrypt(options).then(ciphertext => {
alert(ciphertext.data);
})
}
} else{
window.alert("This browser does not support basic cryptography!");
}
}
encryptMessage();
However, if I copy exactly that code and try to run it locally (using the same cdn of that fiddle) I get the following error:
Uncaught (in promise) Error: Error encrypting message: No keys, passwords, or session key provided.
How can I fix it?