Class SymmetricKey

All Implemented Interfaces:
Serializable, Block, Dumpable

public class SymmetricKey extends Key implements Serializable
Represents a Symmetric Key in the ASN.1 structure
See Also:
  • Field Details

    • serialVersionUID

      public static final long serialVersionUID
      See Also:
    • key

      protected byte[] key
  • Constructor Details

    • SymmetricKey

      public SymmetricKey() throws IOException
      Throws:
      IOException
    • SymmetricKey

      public SymmetricKey(Algorithm sk) throws IOException
      Throws:
      IOException
    • SymmetricKey

      public SymmetricKey(Algorithm sk, Padding pad, Mode mode) throws IOException

      Creates a new symmetric key according to spec.

      Parameters:
      sk - the algrithm of the symmetric key
      pad - the default padding of the symmetric key
      mode - the default mode of the symmetric key
      Throws:
      IOException - if the algorithm is not known to the subsystem
    • SymmetricKey

      public SymmetricKey(byte[] sk) throws IOException
      Throws:
      IOException
    • SymmetricKey

      public SymmetricKey(byte[] sk, AsymmetricKey deckey) throws IOException

      creates a new symmetric key from the given PKCS#1 blob.

      Parameters:
      sk - a binary PKCS#1 representation of the key to be constructed
      deckey - the decryption key
      Throws:
      IOException - if failing to decrypt the symmetric key
  • Method Details

    • setIv

      public byte[] setIv(byte[] b)

      Sets a initialisation vector to be used by the keys default padding.

      Parameters:
      b - the initialisation vector
      Returns:
      the previously set initialisation vector
    • getIv

      public byte[] getIv()
    • getParameter

      public AlgorithmParameter getParameter()
    • getPadding

      public Padding getPadding()
    • getKeySize

      public int getKeySize()

      Gets the key size from the key generation parameters.

      Returns:
      the key size in bits or -1 if there is no key size set
    • getMode

      public Mode getMode()
    • getAlgorithm

      public Algorithm getAlgorithm()
    • encrypt

      public byte[] encrypt(byte[] b) throws IOException
      Specified by:
      encrypt in class Key
      Throws:
      IOException
    • decrypt

      public byte[] decrypt(byte[] b) throws IOException
      Specified by:
      decrypt in class Key
      Throws:
      IOException
    • parse

      protected final void parse(org.bouncycastle.asn1.ASN1Encodable to) throws IOException
      Specified by:
      parse in class AbstractBlock
      Throws:
      IOException
    • getKey

      public byte[] getKey()
    • setKey

      public byte[] setKey(byte[] b)

      Directly replaces the keys binary representation.

      Parameters:
      b - the binary representation of the symmetric key
      Returns:
      the previously set key
    • toAsn1Object

      public org.bouncycastle.asn1.ASN1Object toAsn1Object(DumpType dumpType) throws IOException
      Description copied from interface: Dumpable

      Dumps an ASN.1 representation of the object.

      Specified by:
      toAsn1Object in interface Dumpable
      Parameters:
      dumpType - the dump type to be used
      Returns:
      the ASN.1 string representation of the object
      Throws:
      IOException - if dumping of the object fails due to an illegal internal state of the object
    • equals

      public boolean equals(Object t)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • dumpValueNotation

      public String dumpValueNotation(String prefix, DumpType dumpType)
      Specified by:
      dumpValueNotation in interface Block
    • toString

      public String toString()

      Gets a textual representation of the objects parameters (without the keys).

      Overrides:
      toString in class Object
      Returns:
      the string