Class SecretKeyPacket

All Implemented Interfaces:
PacketTags, PublicKeyAlgorithmTags, org.bouncycastle.util.Encodable
Direct Known Subclasses:
SecretSubkeyPacket

public class SecretKeyPacket extends ContainedPacket implements PublicKeyAlgorithmTags
Base class for OpenPGP secret (primary) keys.
  • Field Details

  • Constructor Details

    • SecretKeyPacket

      public SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, S2K s2k, byte[] iv, byte[] secKeyData)
      Construct a SecretKeyPacket. Note:
      secKeyData
      needs to be prepared by applying encryption/checksum beforehand.
      Parameters:
      pubKeyPacket - pubkey packet corresponding to this secret key packet.
      encAlgorithm - algorithm id of the symmetric key algorithm that was used to encrypt the secret key material
      s2k - s2k identifier for deriving a key from a passphrase
      iv - IV that was used to encrypt the secret key material
      secKeyData - encrypted/checksum'd secret key material
    • SecretKeyPacket

      public SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, int s2kUsage, S2K s2k, byte[] iv, byte[] secKeyData)
      Construct a SecretKeyPacket or SecretSubkeyPacket. Note:
      secKeyData
      needs to be prepared by applying encryption/checksum beforehand.
      Parameters:
      pubKeyPacket - pubkey packet corresponding to this secret key packet.
      encAlgorithm - algorithm id of the symmetric key algorithm that was used to encrypt the secret key material
      s2kUsage - octet indicating, how the secert key material was protected
      s2k - s2k identifier for deriving a key from a passphrase
      iv - IV that was used to encrypt the secret key material
      secKeyData - encrypted/checksum'd secret key material
    • SecretKeyPacket

      public SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, int aeadAlgorithm, int s2kUsage, S2K s2k, byte[] iv, byte[] secKeyData)
      Construct a SecretKeyPacket or SecretSubkeyPacket. Note:
      secKeyData
      needs to be prepared by applying encryption/checksum beforehand.
      Parameters:
      pubKeyPacket - pubkey packet corresponding to this secret key packet.
      encAlgorithm - algorithm id of the symmetric key algorithm that was used to encrypt the secret key material
      aeadAlgorithm - AEAD algorithm scheme used to protect the secret key material with
      s2kUsage - octet indicating how the secret key material was encrypted
      s2k - s2k identifier for deriving a key from a passphrase
      iv - IV that was used to encrypt the secret key material
      secKeyData - encrypted/checksum'd secret key material
  • Method Details

    • getEncAlgorithm

      public int getEncAlgorithm()
      Return the algorithm ID of the symmetric key algorithm that was used to encrypt the secret key material.
      Returns:
      symmetric key enc algorithm id
    • getAeadAlgorithm

      public int getAeadAlgorithm()
      Return the algorithm ID of the AEAD algorithm that was used to protect the secret key material.
      Returns:
      aead algorithm id
    • getS2KUsage

      public int getS2KUsage()
      Return the S2K usage mode indicating how the secret key material is protected.
      Returns:
      s2k usage
    • getIV

      public byte[] getIV()
      Return the IV that was used to protect the secret key material.
      Returns:
      IV
    • getS2K

      public S2K getS2K()
      Return the S2K identifier describing, how to derive the symmetric key to protect the secret key material with.
      Returns:
      s2k identifier
    • getPublicKeyPacket

      public PublicKeyPacket getPublicKeyPacket()
      Return the public key packet corresponding to the secret key packet.
      Returns:
      public key packet
    • getSecretKeyData

      public byte[] getSecretKeyData()
      Return the encrypted/checksum'd secret key data.
      Returns:
      secret key data
    • getEncodedContents

      public byte[] getEncodedContents() throws IOException
      Return the encoded packet content without packet frame.
      Returns:
      encoded packet contents
      Throws:
      IOException
    • encode

      public void encode(BCPGOutputStream out) throws IOException
      Encode the packet into the given BCPGOutputStream. If the packet output stream has PacketFormat.ROUNDTRIP set, the packet format to encode the packet length with depends on the result of Packet.hasNewPacketFormat(). Otherwise, the packet output stream dictates the packet format.
      Specified by:
      encode in class ContainedPacket
      Parameters:
      out - packet output stream
      Throws:
      IOException