Class SymmetricSecretKey

java.lang.Object
org.bouncycastle.crypto.SymmetricSecretKey
All Implemented Interfaces:
Destroyable, Key, SymmetricKey

public final class SymmetricSecretKey extends Object implements SymmetricKey, Destroyable
Basic class describing a secret key implementation. The key will be zeroized explicitly on garbage collection and is protected from being shared between approved an un-approved threads.

Note: it the module is run under the SecurityManager only invokers with CryptoServicesPermission.FIPS_MODE_EXPORT_SECRET_KEY permission can successfully call the getKeyBytes() method.

  • Constructor Details

    • SymmetricSecretKey

      public SymmetricSecretKey(Algorithm algorithm, byte[] bytes)
      Base constructor.
      Parameters:
      algorithm - the algorithm this secret key is associated with.
      bytes - the bytes representing the key's value.
    • SymmetricSecretKey

      public SymmetricSecretKey(Parameters parameterSet, byte[] bytes)
      Base constructor for a specific algorithm associated with a parameter set.
      Parameters:
      parameterSet - the parameter set with the algorithm this secret key is associated with.
      bytes - the bytes representing the key's value.
  • Method Details

    • getAlgorithm

      public Algorithm getAlgorithm()
      Return the algorithm this secret key is for.
      Specified by:
      getAlgorithm in interface Key
      Returns:
      the secret keys algorithm.
    • getKeyBytes

      public byte[] getKeyBytes()
      Return the bytes representing this keys value.

      See CryptoServicesPermission.FIPS_MODE_EXPORT_SECRET_KEY for the permission associated with this method.

      Specified by:
      getKeyBytes in interface SymmetricKey
      Returns:
      the bytes making up this key.
    • equals

      public boolean equals(Object o)
      Description copied from interface: Key
      Return true if o is an equivalent key to this.
      Specified by:
      equals in interface Key
      Overrides:
      equals in class Object
      Parameters:
      o - object to compare to.
      Returns:
      true if o is the same or equivalent key, false otherwise.
    • hashCode

      public int hashCode()
      Description copied from interface: Key
      Return the hashCode for the key.
      Specified by:
      hashCode in interface Key
      Overrides:
      hashCode in class Object
      Returns:
      the key's hashCode.
    • destroy

      public void destroy() throws DestroyFailedException
      Specified by:
      destroy in interface Destroyable
      Throws:
      DestroyFailedException
    • isDestroyed

      public boolean isDestroyed()
      Specified by:
      isDestroyed in interface Destroyable