Package net.i2p.crypto
Class ElGamalEngine
java.lang.Object
net.i2p.crypto.ElGamalEngine
Wrapper for ElGamal encryption/signature schemes.
Does all of Elgamal now for data sizes of 222 bytes and less. The data to be
encrypted is first prepended with a random nonzero byte, then the 32 bytes
making up the SHA256 of the data, then the data itself. The random byte and
the SHA256 hash is stripped on decrypt so the original data is returned.
Not recommended for new applications.
- Author:
- thecrypto, jrandom
-
Constructor Summary
ConstructorDescriptionElGamalEngine
(I2PAppContext context) The ElGamal engine should only be constructed and accessed through the application context. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
decrypt
(byte[] encrypted, PrivateKey privateKey) Decrypt the databyte[]
encrypt the data to the public keyvoid
restart()
This is now a noop.void
shutdown()
Note that this stops the precalc thread and it cannot be restarted.
-
Constructor Details
-
ElGamalEngine
The ElGamal engine should only be constructed and accessed through the application context. This constructor should only be used by the appropriate application context itself. Starts the YK precalc thread if context is RouterContext or Android.
-
-
Method Details
-
shutdown
public void shutdown()Note that this stops the precalc thread and it cannot be restarted.- Since:
- 0.8.8
-
restart
public void restart()This is now a noop. Cannot be restarted.- Since:
- 0.8.8
-
encrypt
encrypt the data to the public key- Parameters:
data
- data to encrypt, must be 222 bytes or less As the encrypted data may contain a substantial number of zeros if the cleartext is smaller than 222 bytes, it is recommended that the caller pad the cleartext to 222 bytes with random data.publicKey
- public key encrypt to- Returns:
- encrypted data, will be exactly 514 bytes long Contains the two-part encrypted data starting at bytes 0 and 257. If the encrypted parts are smaller than 257 bytes, they will be padded with leading zeros. The parts appear to always be 256 bytes or less, in other words, bytes 0 and 257 are always zero.
-
decrypt
Decrypt the data- Parameters:
encrypted
- encrypted data, must be exactly 514 bytes Contains the two-part encrypted data starting at bytes 0 and 257. If the encrypted parts are smaller than 257 bytes, they must be padded with leading zeros.privateKey
- private key to decrypt with- Returns:
- unencrypted data or null on failure
-