Class DataSigner

java.lang.Object
rs.baselib.crypto.DataSigner

public class DataSigner
extends java.lang.Object
The class for signing and verifying signatures.
Author:
ralph
  • Constructor Summary

    Constructors 
    Constructor Description
    DataSigner()
    Constructor.
    DataSigner​(java.security.KeyPair keyPair)
    Constructor from key pair.
    DataSigner​(java.security.PrivateKey privateKey)
    Constructor from private key.
    DataSigner​(java.security.PrivateKey privateKey, java.security.PublicKey publicKey)
    Constructor from key pair.
    DataSigner​(java.security.PublicKey publicKey)
    Constructor from public key.
  • Method Summary

    Modifier and Type Method Description
    byte[] getByteSignature​(byte[] bytes)
    Creates a signature for the given bytes.
    byte[] getByteSignature​(java.io.InputStream in)
    Creates a signature for the given stream.
    byte[] getByteSignature​(java.io.Reader reader)
    Creates a signature for the given stream.
    byte[] getByteSignature​(java.lang.String str)
    Creates a signature for the given string.
    java.security.PrivateKey getPrivateKey()
    Returns the privateKey.
    java.security.PublicKey getPublicKey()
    Returns the publicKey.
    void setPrivateKey​(java.lang.String privateKey)
    Sets the privateKey.
    void setPrivateKey​(java.security.PrivateKey privateKey)
    Sets the privateKey.
    void setPublicKey​(java.lang.String publicKey)
    Sets the publicKey.
    void setPublicKey​(java.security.PublicKey publicKey)
    Sets the publicKey.
    java.lang.String sign​(byte[] bytes)
    Creates a signature for the given bytes.
    java.lang.String sign​(java.io.InputStream in)
    Creates a signature for the given stream.
    java.lang.String sign​(java.io.Reader reader)
    Creates a signature for the given stream.
    java.lang.String sign​(java.lang.String str)
    Creates a signature for the given string.
    void update​(java.security.Signature signature, java.io.InputStream in)
    Updates the DSA with the bytes from this stream.
    protected void update​(java.security.Signature signature, java.io.Reader reader)
    Updates the DSA with the bytes from this stream.
    boolean verify​(byte[] signature, byte[] data)
    Verifies the signature on the given bytes.
    boolean verify​(byte[] signature, java.io.InputStream in)
    Verifies the signature on the given stream.
    boolean verify​(byte[] signature, java.io.Reader in)
    Verifies the signature on the given stream.
    boolean verify​(java.lang.String signature, java.io.InputStream in)
    Verifies the signature on the given stream.
    boolean verify​(java.lang.String signature, java.io.Reader in)
    Verifies the signature on the given stream.
    boolean verify​(java.lang.String signature, java.lang.String str)
    Verifies the signature on the given string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getPrivateKey

      public java.security.PrivateKey getPrivateKey()
      Returns the privateKey.
      Returns:
      the privateKey
    • setPrivateKey

      public void setPrivateKey​(java.security.PrivateKey privateKey)
      Sets the privateKey.
      Parameters:
      privateKey - the privateKey to set
    • setPrivateKey

      public void setPrivateKey​(java.lang.String privateKey) throws SigningException
      Sets the privateKey.
      Parameters:
      privateKey - the privateKey to set
      Throws:
      SigningException - - when a problem occurs
    • getPublicKey

      public java.security.PublicKey getPublicKey()
      Returns the publicKey.
      Returns:
      the publicKey
    • setPublicKey

      public void setPublicKey​(java.security.PublicKey publicKey)
      Sets the publicKey.
      Parameters:
      publicKey - the publicKey to set
    • setPublicKey

      public void setPublicKey​(java.lang.String publicKey) throws SigningException
      Sets the publicKey.
      Parameters:
      publicKey - the publicKey to set
      Throws:
      SigningException - - when a problem occurs
    • sign

      public java.lang.String sign​(java.io.Reader reader) throws SigningException
      Creates a signature for the given stream.
      Parameters:
      reader - stream to be signed
      Returns:
      signature of the provided stream
      Throws:
      SigningException - - when a problem occurs
    • getByteSignature

      public byte[] getByteSignature​(java.io.Reader reader) throws SigningException
      Creates a signature for the given stream.
      Parameters:
      reader - stream to be signed
      Returns:
      signature of the provided stream
      Throws:
      SigningException - - when a problem occurs
    • sign

      public java.lang.String sign​(java.io.InputStream in) throws SigningException
      Creates a signature for the given stream.
      Parameters:
      in - stream to be signed
      Returns:
      signature of the provided stream
      Throws:
      SigningException - - when a problem occurs
    • getByteSignature

      public byte[] getByteSignature​(java.io.InputStream in) throws SigningException
      Creates a signature for the given stream.
      Parameters:
      in - stream to be signed
      Returns:
      signature of the provided stream
      Throws:
      SigningException - - when a problem occurs
    • update

      public void update​(java.security.Signature signature, java.io.InputStream in) throws SigningException
      Updates the DSA with the bytes from this stream.
      Parameters:
      signature - signature
      in - input stream
      Throws:
      SigningException - when the stream cannot be signed
      SigningException - - when a problem occurs
    • update

      protected void update​(java.security.Signature signature, java.io.Reader reader) throws SigningException
      Updates the DSA with the bytes from this stream.
      Parameters:
      signature - signature
      reader - reader for the input stream
      Throws:
      SigningException - when the signing process fails
    • sign

      public java.lang.String sign​(java.lang.String str) throws SigningException
      Creates a signature for the given string.
      Parameters:
      str - string to be signed
      Returns:
      signature of the provided String
      Throws:
      SigningException - when the stream cannot be signed
    • getByteSignature

      public byte[] getByteSignature​(java.lang.String str) throws SigningException
      Creates a signature for the given string.
      Parameters:
      str - string to be signed
      Returns:
      signature of the provided String
      Throws:
      SigningException - when the stream cannot be signed
    • sign

      public java.lang.String sign​(byte[] bytes) throws SigningException
      Creates a signature for the given bytes.
      Parameters:
      bytes - bytes to be signed
      Returns:
      signature of the provided bytes
      Throws:
      SigningException - when the bytes cannot be signed
    • getByteSignature

      public byte[] getByteSignature​(byte[] bytes) throws SigningException
      Creates a signature for the given bytes.
      Parameters:
      bytes - bytes to be signed
      Returns:
      signature of the provided bytes
      Throws:
      SigningException - when the bytes cannot be signed
    • verify

      public boolean verify​(java.lang.String signature, java.io.InputStream in) throws SigningException
      Verifies the signature on the given stream.
      Parameters:
      signature - signature
      in - stream to be verified
      Returns:
      true if the signature confirms stream integrity
      Throws:
      SigningException - when the signature cannot be verified
    • verify

      public boolean verify​(byte[] signature, java.io.InputStream in) throws SigningException
      Verifies the signature on the given stream.
      Parameters:
      signature - signature
      in - stream to be verified
      Returns:
      true if the signature confirms stream integrity
      Throws:
      SigningException - when the signature cannot be verified
    • verify

      public boolean verify​(java.lang.String signature, java.io.Reader in) throws SigningException
      Verifies the signature on the given stream.
      Parameters:
      signature - signature
      in - stream to be verified
      Returns:
      true if the signature confirms stream integrity
      Throws:
      SigningException - when the signature cannot be verified
    • verify

      public boolean verify​(byte[] signature, java.io.Reader in) throws SigningException
      Verifies the signature on the given stream.
      Parameters:
      signature - signature
      in - stream to be verified
      Returns:
      true if the signature confirms stream integrity
      Throws:
      SigningException - when the signature cannot be verified
    • verify

      public boolean verify​(java.lang.String signature, java.lang.String str) throws SigningException
      Verifies the signature on the given string.
      Parameters:
      signature - signature
      str - string to be verified
      Returns:
      true if the signature confirms string integrity
      Throws:
      SigningException - when the signature cannot be verified
    • verify

      public boolean verify​(byte[] signature, byte[] data) throws SigningException
      Verifies the signature on the given bytes.
      Parameters:
      signature - signature
      data - bytes to be verified
      Returns:
      true if the signature confirms data integrity
      Throws:
      SigningException - when the signature cannot be verified