{"record":{"id":"1039fe8c1eaf64ec","repo":"gchq/CyberChef","slug":"enter-the-public-key-of-the-recipient","errorCode":null,"errorMessage":"Enter the public key of the recipient.","messagePattern":"Enter the public key of the recipient\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"warning","filePath":"src/core/operations/PGPEncrypt.mjs","lineNumber":60,"sourceCode":"                \"type\": \"text\",\n                \"value\": \"\"\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     *\n     * @throws {OperationError} if failed private key import or failed encryption\n     */\n    async run(input, args) {\n        const plaintextMessage = input,\n            plainPubKey = args[0];\n        let encryptedMessage;\n\n        if (!plainPubKey) throw new OperationError(\"Enter the public key of the recipient.\");\n\n        const key = await importPublicKey(plainPubKey);\n\n        try {\n            encryptedMessage = await promisify(kbpgp.box)({\n                \"msg\": plaintextMessage,\n                \"encrypt_for\": key,\n                \"asp\": ASP\n            });\n        } catch (err) {\n            throw new OperationError(`Couldn't encrypt message with provided public key: ${err}`);\n        }\n\n        return encryptedMessage.toString();\n    }\n\n}\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/PGPEncrypt.mjs#L42-L78","documentation":"PGPEncrypt.run reads args[0] as the recipient's public key. If it is falsy the operation aborts before importing any key - there is no key to encrypt for. This is an input-validation guard.","triggerScenarios":"The 'Public key of recipient' argument is empty; the args array is missing element 0; the key text was not bound into the recipe.","commonSituations":"User forgot to paste the recipient public key; programmatic call with a missing argument; blank UI field.","solutions":["Provide the recipient's ASCII-armoured PGP public key in the first argument.","Verify the key begins with '-----BEGIN PGP PUBLIC KEY BLOCK-----'.","Ensure the key has an encryption-capable subkey."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const plainPubKey = args[0];\nif (!plainPubKey || !plainPubKey.trim()) {\n    throw new Error('Recipient public key argument is required before running PGP Encrypt.');\n}","typeGuard":"const isArmouredPublicKey = (s) =>\n    typeof s === 'string' && /-----BEGIN PGP PUBLIC KEY BLOCK-----/.test(s);","tryCatchPattern":null,"preventionTips":["Populate the recipient public-key argument before running.","Validate the key is an armoured PGP public key block.","Ensure the key has an encryption-capable subkey."],"tags":["pgp","validation","kbpgp","cryptography"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}