Up: Encrypt
The function
gpgme_op_encryptencrypts the plaintext in the data object plain for the recipients recp and stores the ciphertext in the data object cipher. The type of the ciphertext created is determined by the ASCII armor and text mode attributes set for the context ctx.key must be a
NULL-terminated array of keys. The user must keep references for all keys during the whole duration of the call (but seegpgme_op_encrypt_startfor the requirements with the asynchronous variant).The value in flags is a bitwise-or combination of one or multiple of the following bit values:
GPGME_ENCRYPT_ALWAYS_TRUST- The
GPGME_ENCRYPT_ALWAYS_TRUSTsymbol specifies that all the recipients in recp should be trusted, even if the keys do not have a high enough validity in the keyring. This flag should be used with care; in general it is not a good idea to use any untrusted keys.If
GPG_ERR_UNUSABLE_PUBKEYis returned, some recipients in recp are invalid, but not all. In this case the plaintext might be encrypted for all valid recipients and returned in cipher (if this happens depends on the crypto engine). More information about the invalid recipients is available withgpgme_op_encrypt_result.If recp is
NULL, symmetric rather than public key encryption is performed. Symmetrically encrypted cipher text can be deciphered withgpgme_op_decrypt. Note that in this case the crypto backend needs to retrieve a passphrase from the user. Symmetric encryption is currently only supported for the OpenPGP crypto backend.The function returns the error code
GPG_ERR_NO_ERRORif the ciphertext could be created successfully,GPG_ERR_INV_VALUEif ctx, recp, plain or cipher is not a valid pointer,GPG_ERR_UNUSABLE_PUBKEYif recp contains some invalid recipients,GPG_ERR_BAD_PASSPHRASEif the passphrase for the symmetric key could not be retrieved, and passes through any errors that are reported by the crypto engine support routines.
The function
gpgme_op_encrypt_startinitiates agpgme_op_encryptoperation. It can be completed by callinggpgme_waiton the context. See Waiting For Completion.References to the keys only need to be held for the duration of this call. The user can release its references to the keys after this function returns, even if the operation is not yet finished.
The function returns the error code
GPG_ERR_NO_ERRORif the operation could be started successfully,GPG_ERR_INV_VALUEif ctx, rset, plain or cipher is not a valid pointer, andGPG_ERR_UNUSABLE_PUBKEYif rset does not contain any valid recipients.
This is a pointer to a structure used to store the result of a
gpgme_op_encryptoperation. After successfully encrypting data, you can retrieve the pointer to the result withgpgme_op_encrypt_result. The structure contains the following members:
gpgme_invalid_key_t invalid_recipients- A linked list with information about all invalid keys for which the data could not be encrypted.
The function
gpgme_op_encrypt_resultreturns agpgme_encrypt_result_tpointer to a structure holding the result of agpgme_op_encryptoperation. The pointer is only valid if the last operation on the context was agpgme_op_encrypt,gpgme_op_encrypt_start,gpgme_op_signorgpgme_op_sign_startoperation. If this operation failed, this might be aNULLpointer. The returned pointer is only valid until the next operation is started on the context.
The function
gpgme_op_encrypt_signdoes a combined encrypt and sign operation. It is used likegpgme_op_encrypt, but the ciphertext also contains signatures for the signers listed in ctx.The combined encrypt and sign operation is currently only available for the OpenPGP crypto engine.
The function
gpgme_op_encrypt_sign_startinitiates agpgme_op_encrypt_signoperation. It can be completed by callinggpgme_waiton the context. See Waiting For Completion.The function returns the error code
GPG_ERR_NO_ERRORif the operation could be started successfully, andGPG_ERR_INV_VALUEif ctx, rset, plain or cipher is not a valid pointer.