Class C509PrivateKey
java.lang.Object
org.bouncycastle.cbor.c509.C509PrivateKey
- All Implemented Interfaces:
Destroyable
A C509 private key structure (Section 3.6 of draft-ietf-cose-cbor-encoded-cert-20):
C509PrivateKey = [ C509PrivateKeyType: int, subjectPrivateKeyAlgorithm: AlgorithmIdentifier, subjectPrivateKey: any, ]For type 0 the subjectPrivateKey is the PrivateKey OCTET STRING value field of RFC 5958 as a CBOR byte string; for type 1 it is a COSE_Key structure (RFC 9052), carried here uninterpreted. The subjectPrivateKeyAlgorithm draws from the C509 Public Key Algorithms Registry (Section 8.15).
The structure transports secret material, so it is Destroyable: after
destroy() the key bytes are zeroized and the accessors fail.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intsubjectPrivateKey is the RFC 5958 PrivateKey OCTET STRING value field as a byte string.static final intsubjectPrivateKey is a COSE_Key structure (RFC 9052) containing a private key. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()booleanstatic C509PrivateKeyfromPrivateKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo privateKeyInfo) Build a type 0 C509 private key from a PKCS#8 / RFC 5958 PrivateKeyInfo.byte[]Return the complete CBOR encoding of this structure.static C509PrivateKeygetInstance(byte[] encoding) Parse a C509 private key structure from its CBOR encoding.intReturn the private key type (TYPE_ASYMMETRIC_KEY_PACKAGEorTYPE_COSE_KEY).Return the subject private key algorithm.byte[]Return the CBOR encoding of the subjectPrivateKey item - the key material.inthashCode()booleanorg.bouncycastle.asn1.pkcs.PrivateKeyInfoReturn the PKCS#8 / RFC 5958 PrivateKeyInfo view of a type 0 C509 private key.toString()
-
Field Details
-
TYPE_ASYMMETRIC_KEY_PACKAGE
public static final int TYPE_ASYMMETRIC_KEY_PACKAGEsubjectPrivateKey is the RFC 5958 PrivateKey OCTET STRING value field as a byte string.- See Also:
-
TYPE_COSE_KEY
public static final int TYPE_COSE_KEYsubjectPrivateKey is a COSE_Key structure (RFC 9052) containing a private key.- See Also:
-
-
Method Details
-
getInstance
Parse a C509 private key structure from its CBOR encoding.- Throws:
IOException
-
fromPrivateKeyInfo
public static C509PrivateKey fromPrivateKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo privateKeyInfo) throws IOException Build a type 0 C509 private key from a PKCS#8 / RFC 5958 PrivateKeyInfo. The privateKeyAlgorithm becomes the subjectPrivateKeyAlgorithm and the PrivateKey OCTET STRING value field the subjectPrivateKey.- Throws:
IOException
-
toPrivateKeyInfo
Return the PKCS#8 / RFC 5958 PrivateKeyInfo view of a type 0 C509 private key.- Throws:
IllegalStateException- if this is a type 1 (COSE_Key) structure or the key has been destroyed.IOException
-
getPrivateKeyType
public int getPrivateKeyType()Return the private key type (TYPE_ASYMMETRIC_KEY_PACKAGEorTYPE_COSE_KEY). -
getSubjectPrivateKeyAlgorithm
Return the subject private key algorithm. -
getSubjectPrivateKeyEncoding
public byte[] getSubjectPrivateKeyEncoding()Return the CBOR encoding of the subjectPrivateKey item - the key material. -
getEncoded
Return the complete CBOR encoding of this structure.- Throws:
IOException
-
destroy
- Specified by:
destroyin interfaceDestroyable- Throws:
DestroyFailedException
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-
equals
-
hashCode
-
toString
-