Class MessageDigestCipher

  • All Implemented Interfaces:
    ICipher, ICipherSpi

    public class MessageDigestCipher
    extends AbstractCipher
    Uses a MessageDigest algorithm to encrypt data.

    In this cipher's configuration, the value of algorithm element is used to specify the MessageDigest algorithm; and the provider element may optionally be used to specify the MessageDigest provider.

    Since:
    5.5.0
    Version:
    $Revision$ $Date$
    See Also:
    MessageDigest
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.security.MessageDigest createMessageDigest()
      Returns a new MessageDigest instance based on this cipher's getAlgorithm() and getProvider().
      byte[] decrypt​(byte[] value)
      Decrypts an array of bytes.
      byte[] encrypt​(byte[] value)
      Encrypts an array of bytes.
      protected java.lang.String getAlgorithm()
      Returns the message digest algorithm to be used.
      protected java.lang.String getProvider()
      Returns the message digest provider to be used.
      protected boolean getUseURLSafeBase64Variant()
      Indicates if a URL safe Base64 variant is to be used when encoding bytes to String.
      void init​(org.w3c.dom.Node configuration)
      This method is called only once and before any other method are called.
      protected void setAlgorithm​(java.lang.String algorithm)
      Sets the message digest algorithm to be used.
      protected void setProvider​(java.lang.String provider)
      Sets the message digest provider to be used.
      • Methods inherited from class java.lang.Object

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

      • MessageDigestCipher

        public MessageDigestCipher()
    • Method Detail

      • getUseURLSafeBase64Variant

        protected boolean getUseURLSafeBase64Variant()
        Description copied from class: AbstractCipher
        Indicates if a URL safe Base64 variant is to be used when encoding bytes to String.

        The default value is true. This method may be overridden to change it.

        Overrides:
        getUseURLSafeBase64Variant in class AbstractCipher
        Returns:
        true if a URL safe variant is to be used, false if the standard Base64 is to be used.
      • getAlgorithm

        protected java.lang.String getAlgorithm()
        Returns the message digest algorithm to be used.
        Returns:
        the algorithm.
        Since:
        5.5.0
      • setAlgorithm

        protected void setAlgorithm​(java.lang.String algorithm)
        Sets the message digest algorithm to be used.
        Parameters:
        algorithm - the algorithm.
        Since:
        5.5.0
      • getProvider

        protected java.lang.String getProvider()
        Returns the message digest provider to be used.
        Returns:
        the provider, or null if the default provider search is to be used.
        Since:
        5.5.0
      • setProvider

        protected void setProvider​(java.lang.String provider)
        Sets the message digest provider to be used.
        Parameters:
        provider - the provider, or null if the default provider search is to be used.
        Since:
        5.5.0
      • init

        public void init​(org.w3c.dom.Node configuration)
                  throws PortalException
        Description copied from interface: ICipherSpi
        This method is called only once and before any other method are called. This allows the cipher to initialize itself and read any custom configuration.
        Throws:
        PortalException
      • createMessageDigest

        protected java.security.MessageDigest createMessageDigest()
        Returns a new MessageDigest instance based on this cipher's getAlgorithm() and getProvider().
        Returns:
        the message digest.
        Since:
        5.5.0
        See Also:
        MessageDigest.getInstance(String, String)
      • encrypt

        public byte[] encrypt​(byte[] value)
        Description copied from interface: ICipher
        Encrypts an array of bytes.
        Parameters:
        value - the original value.
        Returns:
        the encrypted value.
      • decrypt

        public byte[] decrypt​(byte[] value)
        Description copied from interface: ICipher
        Decrypts an array of bytes.
        Parameters:
        value - the encrypted value.
        Returns:
        the value decrypted.