Class AbstractSignature

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String algorithm  
      private java.security.Signature signatureInstance  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractSignature​(java.lang.String algorithm)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.security.Signature doInitSignature​(SessionContext session, java.lang.String algo, java.security.Key key, boolean forSigning)
      Initializes the internal signature instance
      protected boolean doVerify​(byte[] data)  
      protected java.util.AbstractMap.SimpleImmutableEntry<java.lang.String,​byte[]> extractEncodedSignature​(byte[] sig)
      Makes an attempt to detect if the signature is encoded or pure data
      java.lang.String getAlgorithm()  
      protected java.security.Signature getSignature()  
      void initSigner​(SessionContext session, java.security.PrivateKey key)  
      void initVerifier​(SessionContext session, java.security.PublicKey key)  
      byte[] sign​(SessionContext session)
      Compute the signature
      java.lang.String toString()  
      void update​(SessionContext session, byte[] hash, int off, int len)
      Update the computed signature with the given data
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • signatureInstance

        private java.security.Signature signatureInstance
      • algorithm

        private final java.lang.String algorithm
    • Constructor Detail

      • AbstractSignature

        protected AbstractSignature​(java.lang.String algorithm)
    • Method Detail

      • doInitSignature

        protected java.security.Signature doInitSignature​(SessionContext session,
                                                          java.lang.String algo,
                                                          java.security.Key key,
                                                          boolean forSigning)
                                                   throws java.security.GeneralSecurityException
        Initializes the internal signature instance
        Parameters:
        session - The SessionContext for calling this method - may be null if not called within a session context
        algo - The signature's algorithm name
        key - the Key that is provided for initialization - a PrivateKey for signing and a PublicKey for verification
        forSigning - If true then it is being initialized for signing, otherwise for verifying a signature
        Returns:
        The Signature instance
        Throws:
        java.security.GeneralSecurityException - if failed to initialize
      • sign

        public byte[] sign​(SessionContext session)
                    throws java.lang.Exception
        Description copied from interface: Signature
        Compute the signature
        Specified by:
        sign in interface Signature
        Parameters:
        session - The SessionContext for calling this method - may be null if not called within a session context
        Returns:
        The signature value
        Throws:
        java.lang.Exception - If failed to calculate the signature
      • initVerifier

        public void initVerifier​(SessionContext session,
                                 java.security.PublicKey key)
                          throws java.lang.Exception
        Specified by:
        initVerifier in interface Signature
        Parameters:
        session - The SessionContext for calling this method - may be null if not called within a session context
        key - The PublicKey to be used for verifying signatures
        Throws:
        java.lang.Exception - If failed to initialize
      • initSigner

        public void initSigner​(SessionContext session,
                               java.security.PrivateKey key)
                        throws java.lang.Exception
        Specified by:
        initSigner in interface Signature
        Parameters:
        session - The SessionContext for calling this method - may be null if not called within a session context
        key - The PrivateKey to be used for signing
        Throws:
        java.lang.Exception - If failed to initialize
      • update

        public void update​(SessionContext session,
                           byte[] hash,
                           int off,
                           int len)
                    throws java.lang.Exception
        Description copied from interface: Signature
        Update the computed signature with the given data
        Specified by:
        update in interface Signature
        Parameters:
        session - The SessionContext for calling this method - may be null if not called within a session context
        hash - The hash data buffer
        off - Offset of hash data in buffer
        len - Length of hash data
        Throws:
        java.lang.Exception - If failed to update
      • extractEncodedSignature

        protected java.util.AbstractMap.SimpleImmutableEntry<java.lang.String,​byte[]> extractEncodedSignature​(byte[] sig)
        Makes an attempt to detect if the signature is encoded or pure data
        Parameters:
        sig - The original signature
        Returns:
        A AbstractMap.SimpleImmutableEntry where first value is the key type and second value is the data - null if not encoded
      • doVerify

        protected boolean doVerify​(byte[] data)
                            throws java.security.SignatureException
        Throws:
        java.security.SignatureException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object