functionstr2ab(str) { const buf = newArrayBuffer(str.length); const bufView = newUint8Array(buf); for (let i = 0, strLen = str.length; i < strLen; i ++) { bufView[i] = str.charCodeAt(i); } return buf; }
functionimportRsaKey(pem) { // fetch the part of the PEM string between header and footer const pemHeader = "--- --BEGIN PUBLIC KEY--- --"; const pemFooter = "--- --END PUBLIC KEY--- --"; const pemContents = pem.substring(pemHeader.length, pem.length - pemFooter.length); // base64 decode the string to get the binary data const binaryDerString = window.atob(pemContents); // convert from a binary string to an ArrayBuffer const binaryDer = str2ab(binaryDerString);