亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ReferenceError:openpgp 未定義

ReferenceError:openpgp 未定義

慕婉清6462132 2023-11-02 22:40:41
我正在創建一個簡單的 chrome 擴展,可以使用 openPGP 的庫加密和解密字符串。但是,我似乎無法定義 openGPG 并且不斷收到錯誤:ReferenceError: openpgp is not defined我已經在 HTML 文件中定義了 openGPG 庫,我認為它可以在全球范圍內使用,對嗎?我的 HTML 和 JS 代碼如下用我的加密的JS文件。非常早期的版本,但只是想在定義鍵并添加該邏輯之前運行它。    document.getElementById("encryptTest").addEventListener('click', () => {        console.log("Popup DOM fully loaded and parsed");            async function encryptString() {            // put keys in backtick (``) to avoid errors caused by spaces or tabs            const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----        ...        -----END PGP PUBLIC KEY BLOCK-----`;            const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK-----        ...        -----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key            const passphrase = `yourPassphrase`; // what the private key is encrypted with                    const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);            await privateKey.decrypt(passphrase);                    const { data: encrypted } = await openpgp.encrypt({                message: openpgp.message.fromText('Hello, World!'),                 // input as Message object                publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for encryption                privateKeys: [privateKey]                                           // for signing (optional)            });            console.log(encrypted); // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'            const { data: decrypted } = await openpgp.decrypt({                message: await openpgp.message.readArmored(encrypted),              // parse armored message                publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for verification (optional)                privateKeys: [privateKey]                                           // for decryption            });            console.log(decrypted); // 'Hello, World!'        });    });
查看完整描述

1 回答

?
千巷貓影

TA貢獻1829條經驗 獲得超7個贊

我認為問題在于該函數在您的代碼中是孤立的。還要確保在 HTML 文件中正確定義它。歡迎來到堆棧溢出:)!



查看完整回答
反對 回復 2023-11-02
  • 1 回答
  • 0 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號