Class SensitiveKeysParser
- java.lang.Object
-
- org.certificateservices.messages.sensitivekeys.SensitiveKeysParser
-
public class SensitiveKeysParser extends java.lang.ObjectClass to generate and parse Sensitive Keys Structures. It has also methods to create encrypted binary data defined in the credential managment protocol 2.0 specification.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classSensitiveKeysParser.SensitiveKeysParserLSResourceResolver
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_VERSIONstatic java.lang.StringNAMESPACEstatic java.lang.StringSENSITIVE_KEYS_XSD_SCHEMA_RESOURCE_LOCATION
-
Constructor Summary
Constructors Constructor Description SensitiveKeysParser(MessageSecurityProvider securityProvider)Constructor for Sensitive Keys Parser, this is the default method to create a parser, it should not be fetched by the PayloadParserRegistry since this is not a CSMessagePayload.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyDatadecryptAndParse(byte[] encryptedData)Method to decrypt and unmarshall a sensitive key data.protected EncodedKeyencodeKey(java.security.Key key)byte[]encryptAndMarshall(KeyData key, java.util.List<java.security.cert.X509Certificate> recipients)Method to serialize and encrypt a sensitive key data to a given list of recipients.KeyDatagenKeyData(java.security.Key symmetricKey)Method to create a key data for a symmetric java.security.Key.KeyDatagenKeyData(java.security.KeyPair asymmetricKey)Method to convert an asymmetric key pair.KeyDatagenKeyData(EncodedKey symmetricKey)Method to create a key data for a symmetric key.KeyDatagenKeyData(EncodedKey publicKey, EncodedKey privateKey)Method to create a key data for a asymmetric key.java.security.KeyPairgetAssymmetricKey(KeyData keyData)Method to recreate the java.security asymmetric key from a key data.javax.crypto.SecretKeygetSymmetricKey(KeyData keyData)Method to recreate the java.security symmetric key from a key data.byte[]marshall(KeyData key)Method to serialize a sensitive key data to a byte array.KeyDataparse(byte[] data)Method to parse a unencrypted sensitive key data.
-
-
-
Field Detail
-
NAMESPACE
public static java.lang.String NAMESPACE
-
DEFAULT_VERSION
public static java.lang.String DEFAULT_VERSION
-
SENSITIVE_KEYS_XSD_SCHEMA_RESOURCE_LOCATION
public static final java.lang.String SENSITIVE_KEYS_XSD_SCHEMA_RESOURCE_LOCATION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SensitiveKeysParser
public SensitiveKeysParser(MessageSecurityProvider securityProvider) throws MessageProcessingException
Constructor for Sensitive Keys Parser, this is the default method to create a parser, it should not be fetched by the PayloadParserRegistry since this is not a CSMessagePayload.- Parameters:
securityProvider- the security provider to use for encrypting and decrypting messages.- Throws:
MessageProcessingException- if internal problems occurred initializing the parser.
-
-
Method Detail
-
parse
public KeyData parse(byte[] data) throws MessageContentException, MessageProcessingException
Method to parse a unencrypted sensitive key data.- Parameters:
data- a serialized sensitive key XML structure.- Returns:
- a unmarshalled KeyData.
- Throws:
MessageContentException- if xml data was invalidMessageProcessingException- if internal problems occurred unmarshalling the data.
-
decryptAndParse
public KeyData decryptAndParse(byte[] encryptedData) throws MessageContentException, MessageProcessingException, NoDecryptionKeyFoundException
Method to decrypt and unmarshall a sensitive key data.The encrypted data should be a XML Encryption (http://www.w3.org/2001/04/xmlenc#) EncryptedData element..
- Parameters:
encryptedData- the encrypted XML data.- Returns:
- an unmarshalled HardTokenData
- Throws:
MessageContentException- if xml data was invalid.MessageProcessingException- if internal problems occurred unmarshalling or decrypting the data.NoDecryptionKeyFoundException- if decryption key couldn't be found in security provider.
-
genKeyData
public KeyData genKeyData(java.security.KeyPair asymmetricKey)
Method to convert an asymmetric key pair.- Parameters:
asymmetricKey- the java.security.KeyPair to convert, never null-- Returns:
- a newly generated key data.
-
genKeyData
public KeyData genKeyData(EncodedKey publicKey, EncodedKey privateKey)
Method to create a key data for a asymmetric key.- Parameters:
publicKey- the public key of key pair to use, not null.privateKey- the private key of key pair to use, not null.- Returns:
- a newly generated key data.
-
genKeyData
public KeyData genKeyData(java.security.Key symmetricKey)
Method to create a key data for a symmetric java.security.Key.- Parameters:
symmetricKey- the symmetric key to use, not null.- Returns:
- a newly generated key data.
- Throws:
MessageProcessingException- if date convertion fails.
-
genKeyData
public KeyData genKeyData(EncodedKey symmetricKey)
Method to create a key data for a symmetric key.- Parameters:
symmetricKey- the symmetric key to use, not null.- Returns:
- a newly generated key data.
- Throws:
MessageProcessingException- if date convertion fails.
-
getSymmetricKey
public javax.crypto.SecretKey getSymmetricKey(KeyData keyData) throws MessageContentException
Method to recreate the java.security symmetric key from a key data.- Parameters:
keyData- the key data that must contain a symmetric key element.- Returns:
- a secret key.
- Throws:
MessageContentException- if key data didn't contain any valid secret key.
-
getAssymmetricKey
public java.security.KeyPair getAssymmetricKey(KeyData keyData) throws MessageContentException
Method to recreate the java.security asymmetric key from a key data.- Parameters:
keyData- the key data that must contain a asymmetric key element.- Returns:
- a reconstructed key pair..
- Throws:
MessageContentException- if key data didn't contain any valid key pair or had unsupported algorithms.
-
encodeKey
protected EncodedKey encodeKey(java.security.Key key)
-
marshall
public byte[] marshall(KeyData key) throws MessageContentException, MessageProcessingException
Method to serialize a sensitive key data to a byte array.- Parameters:
key- the sensitive key data to serialize- Returns:
- a serialized version of the sensitive key data.
- Throws:
MessageContentException- if hard token data contained invalid content.MessageProcessingException- if internal problems occurred marshalling the data.
-
encryptAndMarshall
public byte[] encryptAndMarshall(KeyData key, java.util.List<java.security.cert.X509Certificate> recipients) throws MessageContentException, MessageProcessingException
Method to serialize and encrypt a sensitive key data to a given list of recipients.The data will first be transformed into a encrypted data.
- Parameters:
key- the sensitive key data to serializerecipients- a list of recipients to encrypt the data to.- Returns:
- a serialized version of the hard token data.
- Throws:
MessageContentException- if hard token data contained invalid content.MessageProcessingException- if internal problems occurred marshalling the data.
-
-