Intel

Developer Zone

PasswordKeyDerivationAlg

com.intel.crypto

Class PasswordKeyDerivationAlg

  • java.lang.Object
    • com.intel.crypto.PasswordKeyDerivationAlg


  • public abstract class PasswordKeyDerivationAlg
    extends java.lang.Object
    This abstract class represents a key derivation algorithm, based on PBKDF2.
    • Field Summary

      Fields
      Modifier and Type Field and Description
      static short HASH_TYPE_SHA1
      A constant indicating the usage of SHA1 hash in the key derivation algorithm
      static short HASH_TYPE_SHA256
      A constant indicating the usage of SHA256 hash in the key derivation algorithm.
      static short PASSWORD_MAX_LENGTH
      A constant indicating the maximum allowed password length
      static short RANDOM_SALT_LENGTH
      A constant indicating the size of the random salt that will be used if no salt is provided
    • Method Summary

      Methods
      Modifier and Type Method and Description
      static PasswordKeyDerivationAlg create()
      Returns an instance of the PasswordKeyDerivationAlg class
      abstract void deriveKey(byte[] password, short passwordIndex, short passwordLength, byte[] key, short keyIndex, short keyLength)
      Creates a key based on the password provided.
      abstract short getHashAlgorithm()
      Returns the currently used hash algorithm.
      abstract int getIterationCount()
      Returns the current number of iterations the algorithm runs
      static int getIterationMaxCount()
      Returns maximum iteration count
      abstract short getSalt(byte[] salt, short saltIndex)
      Returns the currently used salt buffer.
      abstract short getSaltSize()
      Returns the currently salt size
      abstract void setHashAlgorithm(short hashAlg)
      Sets the hash algorithm to be used for key derivation.
      abstract void setIterationCount(int count)
      Sets the number of iterations the algorithm needs to run.
      abstract void setSalt(byte[] salt, short saltIndex, short saltLength)
      Sets the salt value for the algorithm.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, toString
    • Field Detail

      • HASH_TYPE_SHA1

        public static final short HASH_TYPE_SHA1
        A constant indicating the usage of SHA1 hash in the key derivation algorithm
        See Also:
        Constant Field Values
      • HASH_TYPE_SHA256

        public static final short HASH_TYPE_SHA256
        A constant indicating the usage of SHA256 hash in the key derivation algorithm. This is the default algorithm
        See Also:
        Constant Field Values
      • PASSWORD_MAX_LENGTH

        public static final short PASSWORD_MAX_LENGTH
        A constant indicating the maximum allowed password length
        See Also:
        Constant Field Values
      • RANDOM_SALT_LENGTH

        public static final short RANDOM_SALT_LENGTH
        A constant indicating the size of the random salt that will be used if no salt is provided
        See Also:
        Constant Field Values
    • Method Detail

      • setSalt

        public abstract void setSalt(byte[] salt,
                   short saltIndex,
                   short saltLength)
        Sets the salt value for the algorithm. If set to null, will generate a new salt automatically when calling deriveKey(). The new salt will be available using getSalt().
        Parameters:
        salt - The buffer for the salt
        saltIndex - The offset in the salt array
        saltLength - The length of the salt array
      • getSalt

        public abstract short getSalt(byte[] salt,
                    short saltIndex)
                               throws CryptoException
        Returns the currently used salt buffer. If salt was not set, will return the randomly generated salt after deriveKey() is called.
        Parameters:
        salt - The buffer for the salt array.
        saltIndex - The offset in the salt array
        Returns:
        Returns the length of the salt buffer
        Throws:
        NotInitializedException - if the salt is not initialized (setSalt() was not called or set to null, and deriveKey() was not called).
        CryptoException - if some other error occurred
      • getHashAlgorithm

        public abstract short getHashAlgorithm()
        Returns the currently used hash algorithm.
        Returns:
        The currently used hash algorithm.
      • setIterationCount

        public abstract void setIterationCount(int count)
                                        throws CryptoException
        Sets the number of iterations the algorithm needs to run. Must be larger than 0
        Parameters:
        count - The number of iterations the algorithm needs to run
        Throws:
        IllegalParameterException - if the iteration count is not larger than 0, or if the iteration count is bigger than the value returned by getIterationMaxCount().
        CryptoException - if some other error occurred.
      • getSaltSize

        public abstract short getSaltSize()
                                   throws CryptoException
        Returns the currently salt size
        Returns:
        The currently salt size
        Throws:
        CryptoException
      • deriveKey

        public abstract void deriveKey(byte[] password,
                     short passwordIndex,
                     short passwordLength,
                     byte[] key,
                     short keyIndex,
                     short keyLength)
                                throws CryptoException
        Creates a key based on the password provided. The key derivation will use the iteration count set in setIterationCount(). This method must be called once prior to the key derivation. The key derivation will use the salt provided by setSalt() or a random salt with a length of RANDOM_SALT_LENGTH otherwise. The key derivation will use the hash algorithm set by setHashAlgorithm() or the default HASH_TYPE_SHA256 if not called.
        Parameters:
        password - The password buffer to be used. Cannot be null.
        passwordIndex - The offset in the password array
        passwordLength - The length of the password array. Must not be larger than PASSWORD_MAX_LENGTH and bigger than zero.
        key - The key buffer to contain the derived key. Cannot be null.
        keyIndex - The offset in the key array
        keyLength - The length of the key array. Must be bigger than zero.
        Throws:
        NotInitializedException - if setIterationCount() was not called.
        IllegalParameterException - if one or more of the parameters were illegal.
        CryptoException - if some other error occurred
      • getIterationMaxCount

        public static int getIterationMaxCount()
                                        throws CryptoException
        Returns maximum iteration count
        Returns:
        The maximum iteration count
        Throws:
        CryptoException
      • create

        public static PasswordKeyDerivationAlg create()
        Returns an instance of the PasswordKeyDerivationAlg class
        Returns:
        An instance of the PasswordKeyDerivationAlg class