Up: Encrypt
The function
gpgme_op_encrypt
encrypts 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_start
for 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_TRUST
symbol 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_PUBKEY
is 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_ERROR
if the ciphertext could be created successfully,GPG_ERR_INV_VALUE
if ctx, recp, plain or cipher is not a valid pointer,GPG_ERR_UNUSABLE_PUBKEY
if recp contains some invalid recipients,GPG_ERR_BAD_PASSPHRASE
if 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_start
initiates agpgme_op_encrypt
operation. It can be completed by callinggpgme_wait
on 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_ERROR
if the operation could be started successfully,GPG_ERR_INV_VALUE
if ctx, rset, plain or cipher is not a valid pointer, andGPG_ERR_UNUSABLE_PUBKEY
if rset does not contain any valid recipients.
This is a pointer to a structure used to store the result of a
gpgme_op_encrypt
operation. 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_result
returns agpgme_encrypt_result_t
pointer to a structure holding the result of agpgme_op_encrypt
operation. The pointer is only valid if the last operation on the context was agpgme_op_encrypt
,gpgme_op_encrypt_start
,gpgme_op_sign
orgpgme_op_sign_start
operation. If this operation failed, this might be aNULL
pointer. The returned pointer is only valid until the next operation is started on the context.
The function
gpgme_op_encrypt_sign
does 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_start
initiates agpgme_op_encrypt_sign
operation. It can be completed by callinggpgme_wait
on the context. See Waiting For Completion.The function returns the error code
GPG_ERR_NO_ERROR
if the operation could be started successfully, andGPG_ERR_INV_VALUE
if ctx, rset, plain or cipher is not a valid pointer.