Package org.jasypt.iv

Class StringFixedIvGenerator

  • All Implemented Interfaces:
    FixedIvGenerator, IvGenerator

    public class StringFixedIvGenerator
    extends java.lang.Object
    implements FixedIvGenerator

    String based implementation of IvGenerator, that will always return the same initialization vector (IV). This IV is returned as bytes using the specified charset for conversion (UTF-8 by default).

    If the requested IV has a size in bytes smaller than the specified IV, the first n bytes are returned. If it is larger, an exception is thrown.

    This class is thread-safe.

    Since:
    1.9.3
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String charset  
      private static java.lang.String DEFAULT_CHARSET  
      private java.lang.String iv  
      private byte[] ivBytes  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringFixedIvGenerator​(java.lang.String iv)
      Creates a new instance of StringFixedIvGenerator using the default charset.
      StringFixedIvGenerator​(java.lang.String iv, java.lang.String charset)
      Creates a new instance of StringFixedIvGenerator
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] generateIv​(int lengthBytes)
      Return IV with the specified byte length.
      boolean includePlainIvInEncryptionResults()
      As this IV generator provides a fixed IV, its inclusion unencrypted in encryption results is not necessary, and in fact not desirable (so that it remains hidden).
      • Methods inherited from class java.lang.Object

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

      • iv

        private final java.lang.String iv
      • charset

        private final java.lang.String charset
      • ivBytes

        private final byte[] ivBytes
    • Constructor Detail

      • StringFixedIvGenerator

        public StringFixedIvGenerator​(java.lang.String iv)
        Creates a new instance of StringFixedIvGenerator using the default charset.
        Parameters:
        iv - the specified IV.
      • StringFixedIvGenerator

        public StringFixedIvGenerator​(java.lang.String iv,
                                      java.lang.String charset)
        Creates a new instance of StringFixedIvGenerator
        Parameters:
        iv - the specified IV.
        charset - the specified charset
    • Method Detail

      • generateIv

        public byte[] generateIv​(int lengthBytes)
        Return IV with the specified byte length.
        Specified by:
        generateIv in interface IvGenerator
        Parameters:
        lengthBytes - length in bytes.
        Returns:
        the generated IV.
      • includePlainIvInEncryptionResults

        public boolean includePlainIvInEncryptionResults()
        As this IV generator provides a fixed IV, its inclusion unencrypted in encryption results is not necessary, and in fact not desirable (so that it remains hidden).
        Specified by:
        includePlainIvInEncryptionResults in interface IvGenerator
        Returns:
        false