JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/openpgp/4.0.2/compat/openpgp.min.js"></script>
<div id="pubkey" style="display:none;">
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: OpenPGP.js v4.1.0
Comment:...

JavaScript

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();