net.i2p.crypto

## Class DSAEngine

- java.lang.Object
- - net.i2p.crypto.DSAEngine

-     public final class DSAEngine
      extends Object

  Digital signature algorithm engine supporting DSA, ECDSA, RSA, and EdDSA. Provides signing and verification operations for all supported signature types.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DSAEngine(I2PAppContext context)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static SHA1Hash` | `calculateHash(byte[] source, int offset, int len)` Calculate a SHA-1 hash of the source data.
    `static DSAEngine` | `getInstance()`
    `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)
    `Signature` | `sign(byte[] data, SigningPrivateKey signingKey)` Sign using any key type.
    `Signature` | `sign(Hash hash, SigningPrivateKey signingKey)` Nonstandard.
    `Signature` | `sign(InputStream in, SigningPrivateKey signingKey)` Sign using DSA-SHA1 ONLY.
    `Signature` | `sign(SHA1Hash hash, SigningPrivateKey signingKey)` Sign using DSA-SHA1 ONLY.
    `Signature` | `sign(SimpleDataStructure hash, PrivateKey privKey, SigType type)` Generic signature type.
    `Signature` | `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 a signature using any supported signature type.
    `boolean` | `verifySignature(Signature signature, Hash hash, SigningPublicKey verifyingKey)` Nonstandard.
    `boolean` | `verifySignature(Signature signature, InputStream in, SigningPublicKey verifyingKey)` Verify using DSA-SHA1 ONLY
    `boolean` | `verifySignature(Signature signature, SHA1Hash hash, SigningPublicKey verifyingKey)` Verify using DSA-SHA1 ONLY
    `boolean` | `verifySignature(Signature signature, SimpleDataStructure hash, PublicKey pubKey)` Generic signature type.
    `boolean` | `verifySignature(Signature signature, SimpleDataStructure hash, SigningPublicKey verifyingKey)` Generic signature type.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DSAEngine

          public DSAEngine(I2PAppContext context)

  - ### Method Detail

    - #### calculateHash

          public static SHA1Hash calculateHash(byte[] source,
                                               int offset,
                                               int len)

      Calculate a SHA-1 hash of the source data.
      Parameters:
        `source` - the source data
        `offset` - the offset in the source data
        `len` - the length of data to hash
      Returns:
        the SHA-1 hash

    - #### getInstance

          public static DSAEngine getInstance()

    - #### 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(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(Hash hash,
                                SigningPrivateKey signingKey)

      Nonstandard. Used by Syndie.
      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(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

    - #### 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

    - #### 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,
                                         byte[] signedData,
                                         SigningPublicKey verifyingKey)

      Verify a signature using any supported signature type.
      Parameters:
        `signature` - the signature to verify
        `signedData` - the data that was signed
        `verifyingKey` - the public key to verify with
      Returns:
        true if the signature is valid, false otherwise

    - #### verifySignature

          public boolean verifySignature(Signature signature,
                                         Hash hash,
                                         SigningPublicKey verifyingKey)

      Nonstandard. Used by Syndie.

    - #### verifySignature

          public boolean verifySignature(Signature signature,
                                         InputStream in,
                                         SigningPublicKey verifyingKey)

      Verify using DSA-SHA1 ONLY

    - #### 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,
                                         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

    - #### 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