GNU gpg is encryption and signing tool.
The GNU Privacy Guard (GnuPG or GPG) is a free software replacement for the PGP suite of cryptographic software.
Apr 15, 2008 How-To: Import/Export GPG key pair 1 minute read This tutorial will show how you can export and import a set of GPG keys from one computer to another. This way, you can sign/encrypt the same way one different computer. A simple way of doing it would be to: $.
GnuPG encrypts messages using asymmetric keypairs individually generated by GnuPG users. The resulting public keys can be exchanged with other users in a variety of ways, such as Internet key servers. They must always be exchanged carefully to prevent identity spoofing by corrupting public key ↔ ‘owner’ identity correspondences. It is also possible to add a cryptographic digital signature to a message, so the message integrity and sender can be verified, if a particular correspondence relied upon has not been corrupted.
1) Login to your shell account
2) Use gpg command to create the keys$ gpg --gen-key
Output:
3) Now keys generated, you can list your own key using:$ gpg -K
OR$ gpg --list-keys
Output:
In the first screen, you should accept the default option: (1) DSA and ElGamal. This option allows you to create a digital signature and encrypt (and decrypt) with two types of technologies. Type 1 and then press Enter. Next, choose the key size, or how long the key should be. How to: Create a public-private key pair.; 2 minutes to read; In this article. To sign an assembly with a strong name, you must have a public/private key pair. This public and private cryptographic key pair is used during compilation to create a strong-named assembly. You can create a key pair using the Strong Name tool (Sn.exe).
Let us try to understand the line pub 1024D/CA7A8402 2007-02-10:
Most important is the key ID i.e. CA7A8402. Make sure you use powerful passphrase to protect keys and not the easy one.
4) To list secret key, type the command:$ gpg --list-secret-keys
Output:
ADVERTISEMENTS
Next: Signing Keys, Previous: Manipulating Keys, Up: Key Management [Contents][Index]
GPGME provides a set of functions to create public key pairs. Most ofthese functions require the use of GnuPG 2.1 and later; for olderGnuPG versions the gpgme_op_genkey
function can be used.Existing code which wants to update to the new functions or new codewhich shall supports older GnuPG versions may try the new functionsfirst and provide a fallback to the old function if the error codeGPG_ERR_NOT_SUPPORTED
is received.
SINCE: 1.7.0
The function gpgme_op_createkey
generates a new key for theprocotol active in the context ctx. As of now this functiondoes only work for OpenPGP and requires at least version 2.1.13 ofGnuPG.
userid is commonly the mail address associated with the key.GPGME does not require a specific syntax but if more than a mailaddress is given, RFC-822 style format is suggested. The value isexpected to be in UTF-8 encoding (i.e. no IDN encoding for mailaddresses). This is a required parameter.
algo specifies the algorithm for the new key (actually a keypairof public and private key). For a list of supported algorithms, seethe GnuPG manual. If algo is NULL
or the string'default', the key is generated using the default algorithm of theengine. If the string 'future-default' is used the engine may use analgorithm which is planned to be the default in a future release ofthe engine; however existing implementation of the protocol may not beable to already handle such future algorithms. For the OpenPGPprotocol, the specification of a default algorithm, without requestinga non-default usage via flags, triggers the creation of aprimary key plus a secondary key (subkey).
reserved must be set to zero.
expires specifies the expiration time in seconds. If you supply0, a reasonable expiration time is chosen. Use the flagGPGME_CREATE_NOEXPIRE
to create keys that do not expire. Notethat this parameter takes an unsigned long value and not atime_t
to avoid problems on systems which use a signed 32 bittime_t
. Note further that the OpenPGP protocol uses 32 bitvalues for timestamps and thus can only encode dates up to the year2106.
extrakey is currently not used and must be set to NULL
.A future version of GPGME may use this parameter to create X.509 keys.
flags can be set to the bit-wise OR of the following flags:
GPGME_CREATE_SIGN
GPGME_CREATE_ENCR
GPGME_CREATE_CERT
GPGME_CREATE_AUTH
SINCE: 1.7.0
Do not create the key with the default capabilities (key usage) of therequested algorithm but use those explicitly given by these flags:“signing”, “encryption”, “certification”, or “authentication”.The allowed combinations depend on the algorithm.
If any of these flags are set and a default algorithm has beenselected only one key is created in the case of the OpenPGPprotocol.
GPGME_CREATE_NOPASSWD
SINCE: 1.7.0
Request generation of the key without password protection.
GPGME_CREATE_SELFSIGNED
SINCE: 1.7.0
For an X.509 key do not create a CSR but a self-signed certificate.This has not yet been implemented.
GPGME_CREATE_NOSTORE
SINCE: 1.7.0
Do not store the created key in the local key database.This has not yet been implemented.
GPGME_CREATE_WANTPUB
GPGME_CREATE_WANTSEC
SINCE: 1.7.0
Return the public or secret key as part of the result structure.This has not yet been implemented.
GPGME_CREATE_FORCE
Microsoft office home and student 2007 product key generator download. SINCE: 1.7.0
The engine does not allow the creation of a key with a user IDalready existing in the local key database. This flag can be used tooverride this check.
GPGME_CREATE_NOEXPIRE
SINCE: 1.8.0
Request generation of keys that do not expire.
After the operation completed successfully, information about thecreated key can be retrieved with gpgme_op_genkey_result
.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.7.0
The function gpgme_op_createkey_start
initiates agpgme_op_createkey
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
SINCE: 1.7.0
The function gpgme_op_createsubkey
creates and adds a newsubkey to the primary OpenPGP key given by KEY. The onlyallowed protocol in ctx is GPGME_PROTOCOL_OPENPGP
.Subkeys (aka secondary keys) are a concept in the OpenPGP protocol tobind several keys to a primary key. As of now this function requiresat least version 2.1.13 of GnuPG.
key specifies the key to operate on.
algo specifies the algorithm for the new subkey. For a list ofsupported algorithms, see the GnuPG manual. If algo isNULL
or the string 'default', the subkey is generated using thedefault algorithm for an encryption subkey of the engine. If thestring 'future-default' is used the engine may use an encryptionalgorithm which is planned to be the default in a future release ofthe engine; however existing implementation of the protocol may not beable to already handle such future algorithms.
reserved must be set to zero.
expires specifies the expiration time in seconds. If you supply0, a reasonable expiration time is chosen. Use the flagGPGME_CREATE_NOEXPIRE
to create keys that do not expire. Notethat this parameter takes an unsigned long value and not atime_t
to avoid problems on systems which use a signed 32 bittime_t
. Note further that the OpenPGP protocol uses 32 bitvalues for timestamps and thus can only encode dates up to the year2106.
flags takes the same values as described above forgpgme_op_createkey
.
In the Log window, however, you see unexpected output: many titles are listed, including some with ratings other than 10. Generate primary key sql developer.
After the operation completed successfully, information about thecreated key can be retrieved with gpgme_op_genkey_result
.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.7.0
The function gpgme_op_createsubkey_start
initiates agpgme_op_createsubkey
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
SINCE: 1.7.0
The function gpgme_op_adduid
adds a new user ID to the OpenPGPkey given by KEY. Adding additional user IDs after key creationis a feature of the OpenPGP protocol and thus the protocol for thecontext ctx must be set to OpenPGP. As of now this functionrequires at least version 2.1.13 of GnuPG.
key specifies the key to operate on.
userid is the user ID to add to the key. A user ID is commonlythe mail address to be associated with the key. GPGME does notrequire a specific syntax but if more than a mail address is given,RFC-822 style format is suggested. The value is expected to be inUTF-8 encoding (i.e. no IDN encoding for mail addresses). This is arequired parameter.
flags are currently not used and must be set to zero.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.7.0
The function gpgme_op_adduid_start
initiates agpgme_op_adduid
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
SINCE: 1.7.0
The function gpgme_op_revuid
revokes a user ID from the OpenPGPkey given by KEY. Revoking user IDs after key creation is afeature of the OpenPGP protocol and thus the protocol for the contextctx must be set to OpenPGP. As of now this function requires atleast version 2.1.13 of GnuPG.
key specifies the key to operate on.
userid is the user ID to be revoked from the key. The user IDmust be given verbatim because the engine does an exact and casesensitive match. Thus the uid
field from the user ID object(gpgme_user_id_t
) is to be used. This is a required parameter.
flags are currently not used and must be set to zero.
Note that the engine won’t allow to revoke the last valid user ID. Tochange a user ID is better to first add the new user ID, then revokethe old one, and finally publish the key.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.7.0
The function gpgme_op_revuid_start
initiates agpgme_op_revuid
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
SINCE: 1.8.0
The function gpgme_op_set_uid_flag
is used to set flags on auser ID from the OpenPGP key given by KEY. Setting flags onuser IDs after key creation is a feature of the OpenPGP protocol andthus the protocol for the context ctx must be set to OpenPGP.
key specifies the key to operate on. This parameters is required.
userid is the user ID of the key to be manipulated. This user IDmust be given verbatim because the engine does an exact and casesensitive match. Thus the uid
field from the user ID object(gpgme_user_id_t
) is to be used. This is a required parameter.
name names the flag which is to be changed. The only currentlysupported flag is:
primary
This sets the primary key flag on the given user ID. All otherprimary key flag on other user IDs are removed. value must begiven as NULL. For technical reasons this functions bumps thecreation timestamp of all affected self-signatures up by one second.At least GnuPG version 2.1.20 is required.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.8.0
The function gpgme_op_set_uid_flag_start
initiates agpgme_op_set_uid_flag
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
The function gpgme_op_genkey
generates a new key pair in thecontext ctx. The meaning of public and secretdepends on the crypto backend.
GPG does not support public and secret, they should beNULL
. GnuPG will generate a key pair and add it to thestandard key ring. The fingerprint of the generated key is availablewith gpgme_op_genkey_result
.
GpgSM requires public to be a writable data object. GpgSM willgenerate a secret key (which will be stored by gpg-agent
,and return a certificate request in public, which then needs tobe signed by the certification authority and imported before it can beused. GpgSM does not make the fingerprint available.
The argument parms specifies parameters for the key in an stringthat looks something like XML. The details about the format ofparms are specific to the crypto engine used by ctx. Thefirst line of the parameters must be <GnupgKeyParamsformat='internal'>
and the last line must be</GnupgKeyParams>
. Every line in between the first and lastlines is treated as a Header: Value pair. In particular, no XMLescaping is necessary if you need to include the characters <
,>
, or &
.
Here is an example for GnuPG as the crypto engine (all parameters ofOpenPGP key generation are documented in the GPG manual):
Here is an example for GpgSM as the crypto engine (all parameters ofOpenPGP key generation are documented in the GPGSM manual):
Strings should be given in UTF-8 encoding. The only format supportedfor now is “internal”. The content of the GnupgKeyParms
container is passed verbatim to the crypto backend. Controlstatements are not allowed.
After the operation completed successfully, the result can beretrieved with gpgme_op_genkey_result
.
The function returns the error code GPG_ERR_NO_ERROR
if theoperation could be started successfully, GPG_ERR_INV_VALUE
ifparms is not a well-formed string (e.g. does not have theexpected tag-like headers and footers), GPG_ERR_NOT_SUPPORTED
if public or secret is not valid, andGPG_ERR_GENERAL
if no key was created by the backend.
The function gpgme_op_genkey_start
initiates agpgme_op_genkey
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 theoperation could be started successfully, GPG_ERR_INV_VALUE
ifparms is not a valid XML string, andGPG_ERR_NOT_SUPPORTED
if public or secret is notNULL
.
This is a pointer to a structure used to store the result of agpgme_op_genkey
operation. After successfully generating akey, you can retrieve the pointer to the result withgpgme_op_genkey_result
. The structure contains the followingmembers:
unsigned int primary : 1
This flag is set to 1 if a primary key was created and to 0if not.
unsigned int sub : 1
This flag is set to 1 if a subkey was created and to 0 if not.
unsigned int uid : 1
This flag is set to 1 if a user ID was created and to 0 if not.
char *fpr
This is the fingerprint of the key that was created. If both aprimary and a subkey were generated, the fingerprint of the primarykey will be returned. If the crypto engine does not provide thefingerprint, fpr
will be a null pointer.
gpgme_data_t pubkey
SINCE: 1.7.0
This will eventually be used to return the public key. It iscurrently not used.
gpgme_data_t seckey
SINCE: 1.7.0
This will eventually be used to return the secret key. It iscurrently not used.
The function gpgme_op_genkey_result
returns agpgme_genkey_result_t
pointer to a structure holding the result ofa gpgme_op_genkey
operation. The pointer is only valid if thelast operation on the context was a gpgme_op_genkey
orgpgme_op_genkey_start
operation, and if this operation finishedsuccessfully. The returned pointer is only valid until the nextoperation is started on the context.
Next: Signing Keys, Previous: Manipulating Keys, Up: Key Management [Contents][Index]