Package net.i2p.crypto
Class DSAEngine
java.lang.Object
net.i2p.crypto.DSAEngine
Sign and verify using DSA-SHA1 and other signature algorithms.
Also contains methods to sign and verify using a SHA-256 Hash.
The primary implementation is code from TheCryto.
As of 0.8.7, also included is an alternate implementation using java.security libraries, which
is slightly slower. This implementation could in the future be easily modified
to use a new signing algorithm from java.security when we change the signing algorithm.
Params and rv's changed from Hash to SHA1Hash for version 0.8.1
Hash variants of sign() and verifySignature() restored in 0.8.3, required by Syndie.
As of 0.9.9, certain methods support RSA and ECDSA keys and signatures, i.e. all types
specified in SigType. The type is specified by the getType() method in
Signature, SigningPublicKey, and SigningPrivateKey. See Javadocs for individual
methods for the supported types. Methods encountering an unsupported type
will throw an IllegalArgumentException.
EdDSA support added in 0.9.15
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic SHA1Hash
calculateHash
(byte[] source, int offset, int len) Deprecated.unusedstatic DSAEngine
sign
(byte[] data, int offset, int length, SigningPrivateKey signingKey) Sign using any key type as of 0.9.12 (DSA-SHA1 only prior to that)sign
(byte[] data, SigningPrivateKey signingKey) Sign using any key type.sign
(InputStream in, SigningPrivateKey signingKey) Sign using DSA-SHA1 ONLY.sign
(SHA1Hash hash, SigningPrivateKey signingKey) Sign using DSA-SHA1 ONLY.sign
(Hash hash, SigningPrivateKey signingKey) Nonstandard.sign
(SimpleDataStructure hash, PrivateKey privKey, SigType type) Generic signature type.sign
(SimpleDataStructure hash, SigningPrivateKey signingKey) Generic signature type.boolean
verifySignature
(Signature signature, byte[] signedData, int offset, int size, SigningPublicKey verifyingKey) Verify using any sig type as of 0.9.12 (DSA only prior to that)boolean
verifySignature
(Signature signature, byte[] signedData, SigningPublicKey verifyingKey) Verify using any sig type.boolean
verifySignature
(Signature signature, InputStream in, SigningPublicKey verifyingKey) Verify using DSA-SHA1 ONLYboolean
verifySignature
(Signature signature, SHA1Hash hash, SigningPublicKey verifyingKey) Verify using DSA-SHA1 ONLYboolean
verifySignature
(Signature signature, Hash hash, SigningPublicKey verifyingKey) Nonstandard.boolean
verifySignature
(Signature signature, SimpleDataStructure hash, PublicKey pubKey) Generic signature type.boolean
verifySignature
(Signature signature, SimpleDataStructure hash, SigningPublicKey verifyingKey) Generic signature type.
-
Constructor Details
-
DSAEngine
-
-
Method Details
-
getInstance
-
verifySignature
public boolean verifySignature(Signature signature, byte[] signedData, SigningPublicKey verifyingKey) Verify using any sig type. Uses TheCrypto code for DSA-SHA1 unless configured to use the java.security libraries. -
verifySignature
public boolean verifySignature(Signature signature, byte[] signedData, int offset, int size, SigningPublicKey verifyingKey) Verify using any sig type as of 0.9.12 (DSA only prior to that) -
verifySignature
Verify using DSA-SHA1 ONLY -
verifySignature
Verify using DSA-SHA1 ONLY- Parameters:
hash
- SHA-1 hash, NOT a SHA-256 hash
-
verifySignature
Nonstandard. Used by Syndie.- Since:
- 0.8.3 (restored, was removed in 0.8.1 and 0.8.2)
-
verifySignature
public boolean verifySignature(Signature signature, SimpleDataStructure hash, SigningPublicKey verifyingKey) Generic signature type. Warning, nonstandard for EdDSA, double-hashes, not recommended.- Parameters:
hash
- SHA1Hash, Hash, Hash384, or Hash512- Since:
- 0.9.9
-
verifySignature
Generic signature type. If you have a Java pubkey, use this, so you don't lose the key parameters, which may be different than the ones defined in SigType. Warning, nonstandard for EdDSA, double-hashes, not recommended.- Parameters:
hash
- SHA1Hash, Hash, Hash384, or Hash512pubKey
- Java key- Since:
- 0.9.9
-
sign
Sign using any key type. Uses TheCrypto code unless configured to use the java.security libraries.- Returns:
- null on error
-
sign
Sign using any key type as of 0.9.12 (DSA-SHA1 only prior to that)- Returns:
- null on error
-
sign
Sign using DSA-SHA1 ONLY. Reads the stream until EOF. Does not close the stream.- Returns:
- null on error
-
sign
Sign using DSA-SHA1 ONLY.- Parameters:
hash
- SHA-1 hash, NOT a SHA-256 hash- Returns:
- null on error
-
sign
Nonstandard. Used by Syndie.- Returns:
- null on error
- Since:
- 0.8.3 (restored, was removed in 0.8.1 and 0.8.2)
-
sign
Generic signature type. Warning, nonstandard for EdDSA, double-hashes, not recommended.- Parameters:
hash
- SHA1Hash, Hash, Hash384, or Hash512- Returns:
- null on error
- Since:
- 0.9.9
-
sign
Generic signature type. If you have a Java privkey, use this, so you don't lose the key parameters, which may be different than the ones defined in SigType. Warning, nonstandard for EdDSA, double-hashes, not recommended.- Parameters:
hash
- SHA1Hash, Hash, Hash384, or Hash512privKey
- Java keytype
- returns a Signature of this type- Returns:
- null on error
- Since:
- 0.9.9
-
calculateHash
Deprecated.unusedReads the stream until EOF. Does not close the stream.- Returns:
- hash SHA-1 hash, NOT a SHA-256 hash
-
calculateHash
- Returns:
- hash SHA-1 hash, NOT a SHA-256 hash
-