Class Crypt

java.lang.Object
com.basis.filesystem.Crypt

public abstract class Crypt extends Object
Base class and entry point for BBj encryption services. Subclasses must implement a constructor taking three arguments: (Boolean p_constant, String p_password, Map p_modes) for use as the default Crypt subclass.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    decrypt(byte[] p_buffer, int p_offset, int p_length)
    Decrypt an arbitrary buffer.
    abstract void
    decryptBlocks(byte[] p_buffer, int p_offset, int p_length)
    Decrypt a buffer in place that is a multiple of the block size for this Crypt object is applicable.
    byte[]
    encrypt(byte[] p_buffer, int p_offset, int p_length)
    Encrypt an arbitrary buffer.
    abstract void
    encryptBlocks(byte[] p_buffer, int p_offset, int p_length)
    Encrypt a buffer in place that is a multiple of the block size for this Crypt object is applicable.
    abstract int
    Get the preferred block size for this encryption method.
    static Crypt
    getCrypt(byte[] p_init, String p_password)
    Get the appropriate Crypt object given an initialization buffer.
    protected abstract Crypt
    getCryptInstance(byte[] p_init, String p_password)
    Method to see if a registered Crypt subclass can handle a given initialization.
    static Crypt
    getDefaultCrypt(boolean p_constant, String p_password, Map p_modes)
    Get the default Crypt object with either constant or randomized initialization.
    abstract byte[]
    Get the initialization buffer suitable for reconstructing the Crypt object.
    protected static void
    register(Crypt p_crypt)
    Register a subclass of Crypt as available.

    Methods inherited from class java.lang.Object

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

    • Crypt

      public Crypt()
  • Method Details

    • getCrypt

      public static Crypt getCrypt(byte[] p_init, String p_password) throws FilesystemException
      Get the appropriate Crypt object given an initialization buffer.
      Parameters:
      p_init - Intialization buffer.
      p_password - Crypt password.
      Returns:
      Initialized Crypt object.
      Throws:
      FilesystemException - if unable to instantiate appropriate Crypt object.
    • getDefaultCrypt

      public static Crypt getDefaultCrypt(boolean p_constant, String p_password, Map p_modes) throws FilesystemException
      Get the default Crypt object with either constant or randomized initialization.
      Parameters:
      p_modes - Modes for the initialization.
      Returns:
      Crypt with randomized initialization.
      Throws:
      FilesystemException
    • encrypt

      public byte[] encrypt(byte[] p_buffer, int p_offset, int p_length) throws FilesystemException
      Encrypt an arbitrary buffer. The encrypted buffer is returned and can be a different size from the buffer being encrypted.
      Parameters:
      p_buffer - Buffer to encrypt.
      p_offset - Offset into buffer.
      p_length - Length of buffer.
      Returns:
      Encrypted buffer.
      Throws:
      FilesystemException - on error.
    • decrypt

      public byte[] decrypt(byte[] p_buffer, int p_offset, int p_length) throws FilesystemException
      Decrypt an arbitrary buffer. The decrypted buffer is returned and can be a different size from the buffer being decrypted.
      Parameters:
      p_buffer - Buffer to decrypt.
      p_offset - Offset into buffer.
      p_length - Length of buffer.
      Returns:
      Encrypted buffer.
      Throws:
      FilesystemException - on error.
    • getInitialization

      public abstract byte[] getInitialization()
      Get the initialization buffer suitable for reconstructing the Crypt object.
      Returns:
      Initization buffer.
    • getBlockSize

      public abstract int getBlockSize()
      Get the preferred block size for this encryption method. If there is no preferred block size, return a number less than or equal to zero.
      Returns:
      Preferred block size.
    • encryptBlocks

      public abstract void encryptBlocks(byte[] p_buffer, int p_offset, int p_length) throws FilesystemException
      Encrypt a buffer in place that is a multiple of the block size for this Crypt object is applicable.
      Parameters:
      p_buffer - Buffer to encrypt in place.
      p_offset - Offset into buffer.
      p_length - Length of buffer.
      Throws:
      FilesystemException - on error.
    • decryptBlocks

      public abstract void decryptBlocks(byte[] p_buffer, int p_offset, int p_length) throws FilesystemException
      Decrypt a buffer in place that is a multiple of the block size for this Crypt object is applicable.
      Parameters:
      p_buffer - Buffer to decrypt in place.
      p_offset - Offset into buffer.
      p_length - Length of buffer.
      Throws:
      FilesystemException - on error.
    • register

      protected static void register(Crypt p_crypt)
      Register a subclass of Crypt as available.
      Parameters:
      p_crypt - Instance of a Crypt subclass.
    • getCryptInstance

      protected abstract Crypt getCryptInstance(byte[] p_init, String p_password) throws FilesystemException
      Method to see if a registered Crypt subclass can handle a given initialization. This method should return null if the given init is not appropriate for this Crypt subclass.
      Parameters:
      p_init - Initialization buffer.
      p_password - Password.
      Returns:
      Instance of Crypt subclass if appropriate.
      Throws:
      FilesystemException - if this is the appropriate handler for the given initialzation but another problem occurs.