public class AsymmetricKeyPackage extends java.lang.Object implements ASN1Type
An AsymmetricKeyPackage may hold on ore more OneAsymmetricKey elements:
OneAsymmetricKey basically is the same as PKCS#8AsymmetricKeyPackage ::= SEQUENCE SIZE (1..MAX) OF OneAsymmetricKey
PrivateKeyInfo
as specified by by
RFC 5208 but adds the publicKey
field to the PrivateKeyInfo (or
now OneAsymmetricKey) structure (see RFC 5998):
OneAsymmetricKey ::= SEQUENCE { version Version, privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, privateKey PrivateKey, attributes [0] Attributes OPTIONAL, ..., [[2: publicKey [1] PublicKey OPTIONAL ]], ... } PrivateKeyInfo ::= OneAsymmetricKeyBackwards compatibility is maintained by the
version
number
field. IAIK-JCE adds support for the OneAsymmetricKey type by simply
adding the publicKey
field to the PrivateKeyInfo
class.
This allows to use the publicKey
enhancement by all PrivateKey
classes that are extended from PKCS#8 PrivateKeyInfo.
Since OneAsymmetricKey is not implemented in an own class the AsymmetricKeyPackage
can be also seen as a SEQUENCE OF PrivateKeyInfo elements and are handled
as general PrivateKey
elements.
When creating
a new AsymmetricKeyPackage
the OneAsymmetricKey/PrivateKeyInfo element(s) have to be provided as
PrivateKey
objects that must represent PKCS#8 OneAsymmetricKey(s)/
PrivateKeyInfo(s):
PrivateKey[] privateKeys = ...; AsymmetricKeyPackage keyPack = new AsymmetricKeyPackage(privateKeys);When having encoded some AsymmetricKeyPackage:
byte[] encodedKeyPack = keyPack.getEncoded();it maybe read and parsed again by creating a new AsymmetricKeyPackage:
AsymmetricKeyPackage keyPack = new AsymmetricKeyPackage(encodedKeyPack); PrivateKey[] privateKeys = keyPack.getPrivateKeys();
Constructor and Description |
---|
AsymmetricKeyPackage(ASN1Object obj)
Creates an AsymmetricKeyPackage from an ASN1Object.
|
AsymmetricKeyPackage(byte[] arr)
Creates a new AsymmetricKeyPackage from a byte array.
|
AsymmetricKeyPackage(java.io.InputStream is)
Creates a new AsymmetricKeyPackage from an InputStream.
|
AsymmetricKeyPackage(java.security.PrivateKey key)
Creates a new AsymmetricKeyPackage with the given OneAsymmetricKey/PrivateKeyInfo.
|
AsymmetricKeyPackage(java.security.PrivateKey[] keys)
Creates a new AsymmetricKeyPackage with the given OneAsymmetricKey/PrivateKeyInfos.
|
Modifier and Type | Method and Description |
---|---|
void |
addKey(java.security.PrivateKey key)
Adds an OneAsymmetricKey/PrivateKeyInfo.
|
void |
addKeys(java.security.PrivateKey[] keys)
Adds an array of OneAsymmetricKey/PrivateKeyInfos.
|
void |
decode(ASN1Object obj)
Decodes an AsymmetricKeyPackage from an ASN1Object.
|
byte[] |
getEncoded()
Returns this AsymmetricKeyPackage as a DER encoded ASN.1 data structure.
|
java.security.PrivateKey[] |
getKeys()
Gets the OneAsymmetricKey/PrivateKeyInfos contained in the AsymmetricKeyPackage.
|
ASN1Object |
toASN1Object()
Returns this AsymmetricKeyPackage as ASN1Object.
|
java.lang.String |
toString()
Returns a string that represents the contents of this private key.
|
void |
writeTo(java.io.OutputStream os)
Writes this AsymmetricKeyPackage DER encoded to an output stream.
|
public AsymmetricKeyPackage(java.security.PrivateKey key) throws java.security.InvalidKeyException
key
- the OneAsymmetricKey/PrivateKeyInfojava.security.InvalidKeyException
- if the key does not represent an OneAsymmetricKey/PrivateKeyInfo
(does not have "PKCS#8" format)public AsymmetricKeyPackage(java.security.PrivateKey[] keys) throws java.security.InvalidKeyException
keys
- the OneAsymmetricKey/PrivateKeyInfosjava.security.InvalidKeyException
- if the key does not represent an OneAsymmetricKey/PrivateKeyInfo
(does not have "PKCS#8" format)public AsymmetricKeyPackage(ASN1Object obj) throws CodingException
obj
- the AsymmetricKeyPackage as ASN1ObjectCodingException
- if the ASN1Object can not be parsedpublic AsymmetricKeyPackage(java.io.InputStream is) throws CodingException, java.io.IOException
is
- the input stream from where the encoded AsymmetricKeyPackage shall be readCodingException
- if the key package can not be parsedjava.io.IOException
- if an I/O error occurspublic AsymmetricKeyPackage(byte[] arr) throws CodingException
arr
- the array containing the encoded AsymmetricKeyPackageCodingException
- if the key package can not be parsedpublic void addKey(java.security.PrivateKey key) throws java.security.InvalidKeyException
key
- the OneAsymmetricKey/PrivateKeyInfo to be addedjava.security.InvalidKeyException
- if the key does not represent an OneAsymmetricKey/PrivateKeyInfo
(does not have "PKCS#8" format)public void addKeys(java.security.PrivateKey[] keys) throws java.security.InvalidKeyException
keys
- the OneAsymmetricKey/PrivateKeyInfos to be addedjava.security.InvalidKeyException
- if any of the keys does not represent an OneAsymmetricKey/PrivateKeyInfo
(does not have "PKCS#8" format)public java.security.PrivateKey[] getKeys()
public void decode(ASN1Object obj) throws CodingException
decode
in interface ASN1Type
obj
- the AsymmetricKeyPackage as ASN1ObjectCodingException
- if the ASn1Object can not be parsedpublic ASN1Object toASN1Object() throws CodingException
toASN1Object
in interface ASN1Type
if
- the ASN1Object cannot be builtCodingException
- if an de/encoding error occurspublic byte[] getEncoded() throws CodingException
CodingException
- if the encoding failspublic void writeTo(java.io.OutputStream os) throws java.io.IOException, CodingException
os
- the output streamjava.io.IOException
- if an I/O error occursCodingException
- if the encoding failspublic java.lang.String toString()
toString
in class java.lang.Object