pgp - PGP Operations
Overview
The pgp module provides PGP (Pretty Good Privacy) operations including key generation, encryption, decryption, and signing.
Types
KeyPair
PGP key pair containing public and private keys.
GenerateOptions
Options for generating PGP keys.
Key Generation
GenerateKeyPair()
Generate new PGP key pair.
Parameters:
opts- Generation options (nil for defaults)
Returns:
- Generated key pair
- Error if generation fails
Example:
Key Reading
ReadPublicKey()
Read public key from PEM format.
Parameters:
publicKeyPEM- PEM format public key string
Returns:
- Parsed entity list
- Error if parsing fails
Example:
ReadPrivateKey()
Read private key from PEM format.
Parameters:
privateKeyPEM- PEM format private key stringpassphrase- Private key passphrase (empty if not encrypted)
Returns:
- Parsed entity list
- Error if parsing fails
Example:
ReadKeyPair()
Read key pair from PEM format.
Parameters:
publicKeyPEM- PEM format public key stringprivateKeyPEM- PEM format private key stringpassphrase- Private key passphrase
Returns:
- Read key pair
- Error if reading fails
Example:
Encryption
Encrypt()
Encrypt data using public key.
Parameters:
data- Data to encryptpublicKeyPEM- PEM format public key string
Returns:
- Encrypted data
- Error if encryption fails
Example:
EncryptText()
Encrypt data and return ASCII armor format.
Parameters:
data- Data to encryptpublicKeyPEM- PEM format public key string
Returns:
- ASCII armor format encrypted text
- Error if encryption fails
Example:
Decryption
Decrypt()
Decrypt data using private key.
Parameters:
encryptedData- Encrypted dataprivateKeyPEM- PEM format private key stringpassphrase- Private key passphrase
Returns:
- Decrypted data
- Error if decryption fails
Example:
DecryptText()
Decrypt ASCII armor format data.
Parameters:
encryptedText- ASCII armor format encrypted textprivateKeyPEM- PEM format private key stringpassphrase- Private key passphrase
Returns:
- Decrypted data
- Error if decryption fails
Example:
Key Information
GetFingerprint()
Get key fingerprint.
Parameters:
keyPEM- PEM format key string (public or private)
Returns:
- Key fingerprint as hexadecimal string
- Error if reading fails
Example:
Usage Patterns
Key Generation and Storage
Email Encryption
File Encryption
Best Practices
Key Management
Error Handling
Related Documentation
- cryptox - Cryptographic functions
- API Documentation
- Module Overview