Class AbstractCipherExecutor<T,​R>

  • All Implemented Interfaces:
    org.apereo.cas.util.crypto.CipherExecutor<T,​R>, org.apereo.cas.util.crypto.DecodableCipher<T,​R>, org.apereo.cas.util.crypto.EncodableCipher<T,​R>
    Direct Known Subclasses:
    BaseBinaryCipherExecutor, BaseStringCipherExecutor

    public abstract class AbstractCipherExecutor<T,​R>
    extends java.lang.Object
    implements org.apereo.cas.util.crypto.CipherExecutor<T,​R>
    Abstract cipher to provide common operations around signing objects.
    Since:
    4.2
    • Field Summary

      • Fields inherited from interface org.apereo.cas.util.crypto.CipherExecutor

        DEFAULT_CONTENT_ENCRYPTION_ALGORITHM, DEFAULT_STRINGABLE_ENCRYPTION_KEY_SIZE, DEFAULT_STRINGABLE_SIGNING_KEY_SIZE
      • Fields inherited from interface org.apereo.cas.util.crypto.DecodableCipher

        LOGGER
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void configureSigningKey​(java.lang.String signingSecretKey)
      Sets signing key.
      protected void configureSigningKeyFromPrivateKeyResource​(java.lang.String signingSecretKey)
      Configure signing key from private key resource.
      static java.security.PrivateKey extractPrivateKeyFromResource​(java.lang.String signingSecretKey)
      Extract private key from resource private key.
      static java.security.PublicKey extractPublicKeyFromResource​(java.lang.String secretKeyToUse)
      Extract public key from resource public key.
      protected java.lang.String getSigningAlgorithmFor​(java.security.Key signingKey)
      Gets signing algorithm for.
      boolean isEnabled()  
      protected byte[] sign​(byte[] value, java.security.Key signingKey)
      Sign the array by first turning it into a base64 encoded string.
      protected byte[] signWith​(byte[] value, java.lang.String algHeaderValue)
      Sign value with given parameters.
      protected byte[] signWith​(byte[] value, java.lang.String algHeaderValue, java.security.Key key)
      Sign with byte [ ].
      protected byte[] verifySignature​(byte[] value, java.security.Key activeSigningKey)
      Verify signature.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.apereo.cas.util.crypto.CipherExecutor

        getName, getSigningKey
      • Methods inherited from interface org.apereo.cas.util.crypto.DecodableCipher

        decode, decode, decode
      • Methods inherited from interface org.apereo.cas.util.crypto.EncodableCipher

        encode, encode
    • Constructor Detail

      • AbstractCipherExecutor

        public AbstractCipherExecutor()
    • Method Detail

      • extractPrivateKeyFromResource

        public static java.security.PrivateKey extractPrivateKeyFromResource​(java.lang.String signingSecretKey)
        Extract private key from resource private key.
        Parameters:
        signingSecretKey - the signing secret key
        Returns:
        the private key
      • extractPublicKeyFromResource

        public static java.security.PublicKey extractPublicKeyFromResource​(java.lang.String secretKeyToUse)
        Extract public key from resource public key.
        Parameters:
        secretKeyToUse - the secret key to use
        Returns:
        the public key
      • isEnabled

        public boolean isEnabled()
        Specified by:
        isEnabled in interface org.apereo.cas.util.crypto.CipherExecutor<T,​R>
      • sign

        protected byte[] sign​(byte[] value,
                              java.security.Key signingKey)
        Sign the array by first turning it into a base64 encoded string.
        Parameters:
        value - the value
        signingKey - the signing key
        Returns:
        the byte [ ]
      • signWith

        protected byte[] signWith​(byte[] value,
                                  java.lang.String algHeaderValue)
        Sign value with given parameters.
        Parameters:
        value - the value
        algHeaderValue - the alg header value
        Returns:
        the byte [ ]
      • signWith

        protected byte[] signWith​(byte[] value,
                                  java.lang.String algHeaderValue,
                                  java.security.Key key)
        Sign with byte [ ].
        Parameters:
        value - the value
        algHeaderValue - the alg header value
        key - the key
        Returns:
        the byte [ ]
      • configureSigningKey

        protected void configureSigningKey​(java.lang.String signingSecretKey)
        Sets signing key. If the key provided is resolved as a private key, then will create use the private key as is, and will sign values using RSA. Otherwise, AES is used.
        Parameters:
        signingSecretKey - the signing secret key
      • configureSigningKeyFromPrivateKeyResource

        protected void configureSigningKeyFromPrivateKeyResource​(java.lang.String signingSecretKey)
        Configure signing key from private key resource.
        Parameters:
        signingSecretKey - the signing secret key
      • verifySignature

        protected byte[] verifySignature​(byte[] value,
                                         java.security.Key activeSigningKey)
        Verify signature.
        Parameters:
        value - the value
        activeSigningKey - the active signing key
        Returns:
        the value associated with the signature, which may have to be decoded, or null.
      • getSigningAlgorithmFor

        protected java.lang.String getSigningAlgorithmFor​(java.security.Key signingKey)
        Gets signing algorithm for.
        Parameters:
        signingKey - the signing key
        Returns:
        the signing algorithm for