我正在创建一个简单的 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!' }); });
添加回答
举报
0/150
提交
取消