# Encrypt & Decrypt Text

To start encryption and decryption operations, you need to prepare your plain text. In addition, you also need a public key that can perform encryption operations. How to generate such a key can be found in the chapter on generating a key pair.

## Encrypt

The Encrypt operation itself uses a public key and does not require a private key. Remember that whoever you want to send it to encrypts it with whose public key. For people who don't use gpg very often, they often get confused and use their own keys to encrypt ciphertext.

Note that if you want to encrypt your text and send it to "foo", you need to know foo's public key first. Then you need to encrypt your text with foo's public key instead of using your public key. Before encrypting, check to see if the public key has cryptographic capabilities. This can be viewed in the usage column of the key toolbox (the letter E stands for encryption).

It is worth mentioning that if you only use foo's public key to encrypt the ciphertext, no one but foo's own private key can decrypt the ciphertext. There is a situation where you want ciphertexts to be decrypted by multiple people (including yourself), please check their corresponding public keys before doing so. After an encryption operation, if you misuse (some people's public keys are found to be missing), you can use the undo operation to restore your original ciphertext before closing GpgFrontend.

### Only Encrypt

In this case, you only encrypt the ciphertext, and the ciphertext will be shorter. Because in operation, the ciphertext does not contain additional signature information to determine the identity of the encryptor. If you don't want to receive your mestigraphs knowing your identity, use this method to generate your ciphertexts.

After the encrypted operation, there is no additional information display in the information board except for the prompt of whether the operation is successful.


![GIF](https://github.com/saturneric/Blob/blob/master/gif/encrypt.gif?raw=true)

### Encrypt Sign

By encrypting and signing at the same time, not only can the text be protected, but the recipient can also know that thecipher text is from your hand. This encryption is often used in scenarios where both parties need to ensure that the decrypted text is credible, and in general, in that scenario, the upper reaches know each other. The ciphertext generated by this operation is longer because of the additional signature information attached to it.

Before doing so, you only need to select the public key(s) you need to use for encryption.  Halfway through the encryption operation, you'll be asked to choose the private key you need to use for signing. That is, the signer. If you don't find the key you want in the Signaler list, confirm that your private key can be used for encryption and is valid. To check whether the key can be used for signing, please check the usage column in the key toolbox on the right (letter S stands for signature). You can select the public key to use for encryption, or you can select the public key to use for signing.

For this type of ciphertext, you can use the validate operation to see if the ciphertext is trustworthy before decryption.

When the operation is complete, information about the cryptographic operation and the signature operation is displayed in the Infomation Board. You can view information about the signature, such as the pattern of your signature and the algorithm used (you can indirectly see which subkey you used to sign). Please note the distinction between the dates used in your signature messages in UTC and not your local time.

![GIF](https://github.com/saturneric/Blob/blob/master/gif/encrypt-sign.gif?raw=true)

## Decrypt

Paste the ciphertext you obtained directly, gpg will automatically select the appropriate key in the list for decryption. Always remember to decrypt with the private key.

Whether a key pair can be used for decryption will not be displayed in the usage column. You only need to remember that a valid private key can be used to decrypt the ciphertext encrypted with the related public key. 

Regarding whether this key is a public key or a private key, you can check the type column in the key toolbox.

![GIF](https://github.com/saturneric/Blob/blob/master/gif/decrypt.gif?raw=true)

## Decrypt Verify

While decrypting, you can learn some information about the encryptor of the key (if you signed it during encryption).

Whether a key pair can be used for verification will not be displayed in the usage column, you only need to remember a valid public key can be used for verificationWhether a key pair can be used for verification will not be displayed in the usage column, you only need to remember a valid public key can be used for verification.
Regarding whether this key is a public key or a private key, you can check the type column in the key toolbox.

![GIF](https://github.com/saturneric/Blob/blob/master/gif/decrypt-verify.gif?raw=true)
