Class DSAEngine


  • public final class DSAEngine
    extends Object
    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 Detail

    • Method Detail

      • getInstance

        public static DSAEngine 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

        public boolean verifySignature​(Signature signature,
                                       SHA1Hash hash,
                                       SigningPublicKey verifyingKey)
        Verify using DSA-SHA1 ONLY
        Parameters:
        hash - SHA-1 hash, NOT a SHA-256 hash
      • verifySignature

        public boolean verifySignature​(Signature signature,
                                       Hash hash,
                                       SigningPublicKey verifyingKey)
        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

        public boolean verifySignature​(Signature signature,
                                       SimpleDataStructure hash,
                                       PublicKey pubKey)
        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 Hash512
        pubKey - Java key
        Since:
        0.9.9
      • sign

        public Signature sign​(byte[] data,
                              SigningPrivateKey signingKey)
        Sign using any key type. Uses TheCrypto code unless configured to use the java.security libraries.
        Returns:
        null on error
      • sign

        public Signature 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)
        Returns:
        null on error
      • sign

        public Signature sign​(InputStream in,
                              SigningPrivateKey signingKey)
        Sign using DSA-SHA1 ONLY. Reads the stream until EOF. Does not close the stream.
        Returns:
        null on error
      • sign

        public Signature sign​(SHA1Hash hash,
                              SigningPrivateKey signingKey)
        Sign using DSA-SHA1 ONLY.
        Parameters:
        hash - SHA-1 hash, NOT a SHA-256 hash
        Returns:
        null on error
      • sign

        public Signature sign​(Hash hash,
                              SigningPrivateKey signingKey)
        Nonstandard. Used by Syndie.
        Returns:
        null on error
        Since:
        0.8.3 (restored, was removed in 0.8.1 and 0.8.2)
      • sign

        public Signature sign​(SimpleDataStructure hash,
                              SigningPrivateKey signingKey)
        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

        public Signature sign​(SimpleDataStructure hash,
                              PrivateKey privKey,
                              SigType type)
        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 Hash512
        privKey - Java key
        type - returns a Signature of this type
        Returns:
        null on error
        Since:
        0.9.9
      • calculateHash

        public SHA1Hash calculateHash​(InputStream in)
        Deprecated.
        unused
        Reads the stream until EOF. Does not close the stream.
        Returns:
        hash SHA-1 hash, NOT a SHA-256 hash
      • calculateHash

        public static SHA1Hash calculateHash​(byte[] source,
                                             int offset,
                                             int len)
        Returns:
        hash SHA-1 hash, NOT a SHA-256 hash