Class SecretKeyPacket
java.lang.Object
org.bouncycastle.bcpg.Packet
org.bouncycastle.bcpg.ContainedPacket
org.bouncycastle.bcpg.SecretKeyPacket
- All Implemented Interfaces:
PacketTags, PublicKeyAlgorithmTags, org.bouncycastle.util.Encodable
- Direct Known Subclasses:
SecretSubkeyPacket
Base class for OpenPGP secret (primary) keys.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum accepted length of the external key locator hint of a version 4 secret key packet, whose hint is not length-prefixed and so is bounded only by the packet.static final intstatic final intMaximum length of the external key locator hint of a version 5 or 6 secret key packet, whose conditional parameters are prefixed with a one-octet count (RFC 9580 sec.static final intS2K-usage octet indicating that the secret key material is protected using an AEAD scheme.static final intDeprecated.Use of MalleableCFB is deprecated.static final intExternally-backed secret key material.static final intS2K-usage octet indicating that the secret key material is unprotected.static final intS2K-usage octet indicating that the secret key material is protected using a cipher in CFB mode.Fields inherited from interface PacketTags
AEAD_ENC_DATA, COMPRESSED_DATA, EXPERIMENTAL_1, EXPERIMENTAL_2, EXPERIMENTAL_3, EXPERIMENTAL_4, LITERAL_DATA, MARKER, MOD_DETECTION_CODE, ONE_PASS_SIGNATURE, PADDING, PUBLIC_KEY, PUBLIC_KEY_ENC_SESSION, PUBLIC_SUBKEY, RESERVED, SECRET_KEY, SECRET_SUBKEY, SIGNATURE, SYM_ENC_INTEGRITY_PRO, SYMMETRIC_KEY_ENC, SYMMETRIC_KEY_ENC_SESSION, TRUST, USER_ATTRIBUTE, USER_IDFields inherited from interface PublicKeyAlgorithmTags
AEDH, AEDSA, DIFFIE_HELLMAN, DSA, EC, ECDH, ECDSA, Ed25519, Ed448, EDDSA, EDDSA_LEGACY, ELGAMAL_ENCRYPT, ELGAMAL_GENERAL, EXPERIMENTAL_1, EXPERIMENTAL_10, EXPERIMENTAL_11, EXPERIMENTAL_2, EXPERIMENTAL_3, EXPERIMENTAL_4, EXPERIMENTAL_5, EXPERIMENTAL_6, EXPERIMENTAL_7, EXPERIMENTAL_8, EXPERIMENTAL_9, RSA_ENCRYPT, RSA_GENERAL, RSA_SIGN, X25519, X448 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSecretKeyPacket(int keyTag, PublicKeyPacket pubKeyPacket, byte[] locatorHint) Create a SecretKeyPacket representing an external secret key (USAGE_EXTERNAL).SecretKeyPacket(PublicKeyPacket pubKeyPacket, byte[] locatorHint) Create a SecretKeyPacket representing an external secret key (USAGE_EXTERNAL).SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, int aeadAlgorithm, int s2kUsage, S2K s2k, byte[] iv, byte[] secKeyData) Construct aSecretKeyPacketorSecretSubkeyPacket.SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, int s2kUsage, S2K s2k, byte[] iv, byte[] secKeyData) Construct aSecretKeyPacketorSecretSubkeyPacket.SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, S2K s2k, byte[] iv, byte[] secKeyData) Construct aSecretKeyPacket. -
Method Summary
Modifier and TypeMethodDescriptionvoidencode(BCPGOutputStream out) Encode the packet into the givenBCPGOutputStream.intReturn the algorithm ID of the AEAD algorithm that was used to protect the secret key material.intReturn the algorithm ID of the symmetric key algorithm that was used to encrypt the secret key material.byte[]Return the encoded packet content without packet frame.byte[]If the key has external private key material (s2k usageUSAGE_EXTERNAL), return the locator hint data.byte[]getIV()Return the IV that was used to protect the secret key material.Return the public key packet corresponding to the secret key packet.getS2K()Return the S2K identifier describing, how to derive the symmetric key to protect the secret key material with.intReturn the S2K usage mode indicating how the secret key material is protected.byte[]Return the encrypted/checksum'd secret key data.Methods inherited from class ContainedPacket
getEncoded, getEncodedMethods inherited from class Packet
getPacketTag, hasNewPacketFormat, isCritical
-
Field Details
-
MAX_S2K_ENCODING_LEN
public static final int MAX_S2K_ENCODING_LEN- See Also:
-
USAGE_NONE
public static final int USAGE_NONES2K-usage octet indicating that the secret key material is unprotected.- See Also:
-
USAGE_CHECKSUM
public static final int USAGE_CHECKSUMDeprecated.Use of MalleableCFB is deprecated. For v4 keys, useUSAGE_SHA1instead. For v6 keys useUSAGE_AEADinstead.S2K-usage octet indicating that the secret key material is protected using malleable CFB. Malleable-CFB-encrypted keys are vulnerable to corruption attacks that can cause leakage of secret data when the secret key is used.- See Also:
-
USAGE_SHA1
public static final int USAGE_SHA1S2K-usage octet indicating that the secret key material is protected using a cipher in CFB mode. CFB-encrypted keys are vulnerable to corruption attacks that can cause leakage of secret data when the secret key is use.- See Also:
-
USAGE_AEAD
public static final int USAGE_AEADS2K-usage octet indicating that the secret key material is protected using an AEAD scheme. This usage protects against above-mentioned attacks. Passphrase-protected secret key material in a v6 Secret Key or v6 Secret Subkey packet SHOULD be protected with AEAD encryption unless it will be transferred to an implementation that is known to not support AEAD. Users should migrate to AEAD with all due speed.- See Also:
-
USAGE_EXTERNAL
public static final int USAGE_EXTERNALExternally-backed secret key material. S2K-usage octet indicating that the secret key material is stored externally, e.g. on a hardware device. The draft specification is an alternative to GnuPGs proprietaryS2K.GNU_DUMMY_S2Kmechanism.NOTE: this code point is provisional. draft-dkg-openpgp-external-secrets-03 sec. 2 records it as "TBD (252?)" and IANA has not yet assigned it, so the value here tracks the draft's suggestion and is subject to change if a different octet is allocated. Do not rely on it for long-term storage.
- See Also:
-
MAX_EXTERNAL_LOCATOR_HINT_LEN
public static final int MAX_EXTERNAL_LOCATOR_HINT_LENMaximum accepted length of the external key locator hint of a version 4 secret key packet, whose hint is not length-prefixed and so is bounded only by the packet. MirrorsSignaturePacket.MAX_SUBPACKET_LEN.- See Also:
-
MAX_V6_EXTERNAL_LOCATOR_HINT_LEN
public static final int MAX_V6_EXTERNAL_LOCATOR_HINT_LENMaximum length of the external key locator hint of a version 5 or 6 secret key packet, whose conditional parameters are prefixed with a one-octet count (RFC 9580 sec. 5.5.3).- See Also:
-
-
Constructor Details
-
SecretKeyPacket
Create a SecretKeyPacket representing an external secret key (USAGE_EXTERNAL).- Parameters:
pubKeyPacket- public key packetlocatorHint- optional external key locator hint- See Also:
-
SecretKeyPacket
Create a SecretKeyPacket representing an external secret key (USAGE_EXTERNAL).- Parameters:
keyTag- key packet typepubKeyPacket- public key packetlocatorHint- optional external key locator hint- See Also:
-
SecretKeyPacket
public SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, S2K s2k, byte[] iv, byte[] secKeyData) Construct aSecretKeyPacket. 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 materials2k- s2k identifier for deriving a key from a passphraseiv- IV that was used to encrypt the secret key materialsecKeyData- encrypted/checksum'd secret key material
-
SecretKeyPacket
public SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, int s2kUsage, S2K s2k, byte[] iv, byte[] secKeyData) Construct aSecretKeyPacketorSecretSubkeyPacket. 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 materials2kUsage- octet indicating, how the secert key material was protecteds2k- s2k identifier for deriving a key from a passphraseiv- IV that was used to encrypt the secret key materialsecKeyData- encrypted/checksum'd secret key material
-
SecretKeyPacket
public SecretKeyPacket(PublicKeyPacket pubKeyPacket, int encAlgorithm, int aeadAlgorithm, int s2kUsage, S2K s2k, byte[] iv, byte[] secKeyData) Construct aSecretKeyPacketorSecretSubkeyPacket. 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 materialaeadAlgorithm- AEAD algorithm scheme used to protect the secret key materials2kUsage- octet indicating how the secret key material was encrypteds2k- s2k identifier for deriving a key from a passphraseiv- IV that was used to encrypt the secret key materialsecKeyData- 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
Return the S2K identifier describing, how to derive the symmetric key to protect the secret key material with.- Returns:
- s2k identifier
-
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
-
getExternalKeyLocatorHint
public byte[] getExternalKeyLocatorHint()If the key has external private key material (s2k usageUSAGE_EXTERNAL), return the locator hint data. If the locator hint is empty, it is referred to as "best effort". Otherwise, the first octet indicates the type of locator hint.- Returns:
- locator hints data
- See Also:
-
getEncodedContents
Return the encoded packet content without packet frame.- Returns:
- encoded packet contents
- Throws:
IOException
-
encode
Encode the packet into the givenBCPGOutputStream. If the packet output stream hasPacketFormat.ROUNDTRIPset, the packet format to encode the packet length with depends on the result ofPacket.hasNewPacketFormat(). Otherwise, the packet output stream dictates the packet format.- Specified by:
encodein classContainedPacket- Parameters:
out- packet output stream- Throws:
IOException
-