🛠️ToolsShed

PGP Key Generator

Generate RSA or ECC OpenPGP key pairs for email encryption and digital signatures.

Note: Keys are generated using Web Crypto API in your browser. Keys are in PKCS8/SPKI PEM format. Use GPG to convert to OpenPGP format if needed.

Preguntas Frecuentes

Implementación de Código

# pip install pgpy
import pgpy
from pgpy.constants import PubKeyAlgorithm, KeyFlags, HashAlgorithm, SymmetricKeyAlgorithm, CompressionAlgorithm

def generate_pgp_keypair(name: str, email: str, passphrase: str = None):
    """Generate an RSA PGP keypair."""
    key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 4096)
    uid = pgpy.PGPUID.new(name, email=email)
    key.add_uid(
        uid,
        usage={KeyFlags.Sign, KeyFlags.EncryptCommunications},
        hashes=[HashAlgorithm.SHA512, HashAlgorithm.SHA256],
        ciphers=[SymmetricKeyAlgorithm.AES256],
        compression=[CompressionAlgorithm.ZLIB],
    )

    if passphrase:
        key.protect(passphrase, SymmetricKeyAlgorithm.AES256, HashAlgorithm.SHA256)

    public_key = str(key.pubkey)
    private_key = str(key)

    return public_key, private_key

# Generate a keypair
pub, priv = generate_pgp_keypair("Alice Smith", "alice@example.com", "strongpassphrase")
print("=== PUBLIC KEY ===")
print(pub[:100] + "...")
print("=== PRIVATE KEY ===")
print(priv[:100] + "...")

# Encrypt a message
def encrypt_message(public_key_str: str, message: str) -> str:
    pub_key, _ = pgpy.PGPKey.from_blob(public_key_str)
    pgp_msg = pgpy.PGPMessage.new(message)
    encrypted = pub_key.encrypt(pgp_msg)
    return str(encrypted)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.