All cryptographic operations are performed server-side. For production use, generate keys locally and never transmit private keys over the network.
| Parameter | Description | Recommendation |
|---|---|---|
| 160-bit | EC-ElGamal key size | Good for testing |
| 320-bit | Larger EC-ElGamal key | Better security |
| PKCS1 | Standard padding mode | Recommended |
| NoPadding | No padding applied | Use with caution |
ElGamal is an asymmetric key encryption algorithm based on the Diffie-Hellman key exchange, developed by Taher Elgamal in 1985. It provides semantic security, meaning that encrypting the same message twice produces different ciphertexts, making it resistant to chosen-plaintext attacks.
| Algorithm | Security Basis | Ciphertext Size | Semantic Security | Performance |
|---|---|---|---|---|
| ElGamal | Discrete Logarithm | 2x plaintext | Yes | Moderate |
| RSA | Integer Factorization | = key size | With OAEP | Fast |
| ECC | Elliptic Curve DLP | Smaller keys | Yes | Very Fast |
Java (Bouncy Castle)
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ElGamal", "BC");
kpg.initialize(1024);
KeyPair kp = kpg.generateKeyPair();
Cipher cipher = Cipher.getInstance("ElGamal/None/NoPadding", "BC");
cipher.init(Cipher.ENCRYPT_MODE, kp.getPublic());
byte[] ciphertext = cipher.doFinal(plaintext);
Python (PyCryptodome)
from Crypto.PublicKey import ElGamal
from Crypto.Random import get_random_bytes
# Generate key pair
key = ElGamal.generate(2048, get_random_bytes)
public_key = key.publickey()
# ElGamal is typically used with hybrid encryption
# combining with symmetric ciphers like AES
Every coffee helps keep the servers running. Every book sale funds the next tool I'm dreaming up. You're not just supporting a site — you're helping me build what developers actually need.