public class KeyInfoSupport extends Object
Modifier | Constructor and Description |
---|---|
protected |
KeyInfoSupport()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
addCertificate(KeyInfo keyInfo,
X509Certificate cert)
Converts a native Java
X509Certificate into the corresponding XMLObject and stores it
in a KeyInfo in the first X509Data element. |
static void |
addCRL(KeyInfo keyInfo,
X509CRL crl)
|
static void |
addDEREncodedPublicKey(KeyInfo keyInfo,
PublicKey pk)
Converts a Java public key into the corresponding XMLObject and stores it in a
KeyInfo in a
new DEREncodedKeyValue element. |
static void |
addKeyName(KeyInfo keyInfo,
String keyNameValue)
Add a new
KeyName value to a KeyInfo. |
static void |
addPublicKey(KeyInfo keyInfo,
PublicKey pk)
|
static DSAKeyValue |
buildDSAKeyValue(DSAPublicKey dsaPubKey)
Builds a
DSAKeyValue XMLObject from the Java security DSA public key type. |
protected static PublicKey |
buildKey(KeySpec keySpec,
String keyAlgorithm)
Generates a public key from the given key spec.
|
static RSAKeyValue |
buildRSAKeyValue(RSAPublicKey rsaPubKey)
Builds an
RSAKeyValue XMLObject from the Java security RSA public key type. |
static X509Certificate |
buildX509Certificate(X509Certificate cert)
Builds an
X509Certificate XMLObject from a native Java
X509Certificate . |
static X509CRL |
buildX509CRL(X509CRL crl)
|
static X509Digest |
buildX509Digest(X509Certificate javaCert,
String algorithmURI)
Build an
X509Digest containing the digest of the specified certificate. |
static X509IssuerSerial |
buildX509IssuerSerial(String issuerName,
BigInteger serialNumber)
Build an
X509IssuerSerial containing a given issuer name and serial number. |
static X509SKI |
buildX509SKI(X509Certificate javaCert)
Build an
X509SKI containing the subject key identifier extension value contained within a certificate. |
static X509SubjectName |
buildX509SubjectName(String subjectName)
Build an
X509SubjectName containing a given subject name. |
static BigInteger |
decodeBigIntegerFromCryptoBinary(String base64Value)
Decode a base64-encoded ds:CryptoBinary value to a native Java BigInteger type.
|
static String |
encodeCryptoBinaryFromBigInteger(BigInteger bigInt)
Encode a native Java BigInteger type to a base64-encoded ds:CryptoBinary value.
|
static X509Certificate |
getCertificate(X509Certificate xmlCert)
Convert an
X509Certificate into a native Java representation. |
static List<X509Certificate> |
getCertificates(KeyInfo keyInfo)
Get a list of the Java
X509Certificate within the given KeyInfo. |
static List<X509Certificate> |
getCertificates(X509Data x509Data)
Get a list of the Java
X509Certificate within the given X509Data . |
static X509CRL |
getCRL(X509CRL xmlCRL)
Convert an
X509CRL into a native Java representation. |
static List<X509CRL> |
getCRLs(KeyInfo keyInfo)
|
static List<X509CRL> |
getCRLs(X509Data x509Data)
|
static PublicKey |
getDSAKey(DSAKeyValue keyDescriptor)
Builds an DSA key from a
DSAKeyValue element. |
static PublicKey |
getDSAKey(DSAKeyValue keyDescriptor,
DSAParams dsaParams)
Builds a DSA key from an
DSAKeyValue element and the supplied Java DSAParams , which supplies key
material from a shared key family. |
static PublicKey |
getKey(DEREncodedKeyValue keyValue)
Extracts the public key within the
DEREncodedKeyValue . |
static PublicKey |
getKey(KeyValue keyValue)
Extracts the DSA or RSA public key within the
KeyValue . |
static KeyInfoGenerator |
getKeyInfoGenerator(Credential credential,
NamedKeyInfoGeneratorManager manager,
String keyInfoProfileName)
Obtains a
KeyInfoGenerator for the specified Credential . |
static List<String> |
getKeyNames(KeyInfo keyInfo)
Get the set of key names inside the specified
KeyInfo as a list of strings. |
static List<PublicKey> |
getPublicKeys(KeyInfo keyInfo)
|
static PublicKey |
getRSAKey(RSAKeyValue keyDescriptor)
Builds an RSA key from an
RSAKeyValue element. |
protected static CertificateFactory |
getX509CertFactory()
Get the Java certificate factory singleton.
|
static boolean |
hasCompleteDSAParams(DSAKeyValue keyDescriptor)
Check whether the specified
DSAKeyValue element has the all optional DSA values which can be shared
amongst many keys in a DSA "key family", and are presumed to be known from context. |
@Nonnull public static List<String> getKeyNames(@Nullable KeyInfo keyInfo)
KeyInfo
as a list of strings.keyInfo
- KeyInfo
to retrieve key names frompublic static void addKeyName(@Nonnull KeyInfo keyInfo, @Nullable String keyNameValue)
KeyName
value to a KeyInfo.keyInfo
- the KeyInfo to which to add the new valuekeyNameValue
- the new key name value to add@Nonnull public static List<X509Certificate> getCertificates(@Nullable KeyInfo keyInfo) throws CertificateException
X509Certificate
within the given KeyInfo.keyInfo
- key info to extract the certificates fromX509Certificate
sCertificateException
- thrown if there is a problem converting the X509 data into
X509Certificate
s.@Nonnull public static List<X509Certificate> getCertificates(@Nullable X509Data x509Data) throws CertificateException
X509Certificate
within the given X509Data
.x509Data
- X509Data
from which to extract the certificateX509Certificate
sCertificateException
- thrown if there is a problem converting the X509 data into
X509Certificate
s.@Nullable public static X509Certificate getCertificate(@Nullable X509Certificate xmlCert) throws CertificateException
X509Certificate
into a native Java representation.xmlCert
- an X509Certificate
X509Certificate
CertificateException
- thrown if there is a problem converting the X509 data into
X509Certificate
s.@Nonnull public static List<X509CRL> getCRLs(@Nullable KeyInfo keyInfo) throws CRLException
keyInfo
- the KeyInfo
to extract the CRLs fromX509CRL
sCRLException
- thrown if there is a problem converting the CRL data into X509CRL
s@Nonnull public static List<X509CRL> getCRLs(@Nullable X509Data x509Data) throws CRLException
x509Data
- X509Data
to extract the CRLs fromX509CRL
sCRLException
- thrown if there is a problem converting the CRL data into X509CRL
s@Nullable public static X509CRL getCRL(@Nullable X509CRL xmlCRL) throws CRLException
X509CRL
into a native Java representation.xmlCRL
- object to extract the CRL fromX509CRL
objectCRLException
- thrown if there is a problem converting the CRL data into X509CRL
public static void addCertificate(@Nonnull KeyInfo keyInfo, @Nonnull X509Certificate cert) throws CertificateEncodingException
X509Certificate
into the corresponding XMLObject and stores it
in a KeyInfo
in the first X509Data
element. The X509Data element will be created if necessary.keyInfo
- the KeyInfo
object into which to add the certificatecert
- the Java X509Certificate
to addCertificateEncodingException
- thrown when there is an error converting the Java certificate representation
to the XMLObject representationpublic static void addCRL(@Nonnull KeyInfo keyInfo, @Nonnull X509CRL crl) throws CRLException
X509CRL
into the corresponding XMLObject and stores it in a
KeyInfo
in the first X509Data
element. The X509Data element will be created if necessary.keyInfo
- the KeyInfo
object into which to add the CRLcrl
- the Java X509CRL
to addCRLException
- thrown when there is an error converting the Java CRL representation to the XMLObject
representation@Nonnull public static X509Certificate buildX509Certificate(X509Certificate cert) throws CertificateEncodingException
X509Certificate
XMLObject from a native Java
X509Certificate
.cert
- the Java X509Certificate
to convertX509Certificate
XMLObjectCertificateEncodingException
- thrown when there is an error converting the Java certificate representation
to the XMLObject representation@Nonnull public static X509CRL buildX509CRL(X509CRL crl) throws CRLException
crl
- the Java X509CRL
to convertX509CRL
XMLObjectCRLException
- thrown when there is an error converting the Java CRL representation to the XMLObject
representation@Nonnull public static X509SubjectName buildX509SubjectName(@Nullable String subjectName)
X509SubjectName
containing a given subject name.subjectName
- the name content@Nonnull public static X509IssuerSerial buildX509IssuerSerial(@Nullable String issuerName, @Nullable BigInteger serialNumber)
X509IssuerSerial
containing a given issuer name and serial number.issuerName
- the name contentserialNumber
- the serial number content@Nullable public static X509SKI buildX509SKI(@Nonnull X509Certificate javaCert)
X509SKI
containing the subject key identifier extension value contained within a certificate.javaCert
- the Java X509Certificate from which to extract the subject key identifier value.@Nonnull public static X509Digest buildX509Digest(@Nonnull X509Certificate javaCert, @Nonnull String algorithmURI) throws NoSuchAlgorithmException, CertificateEncodingException
X509Digest
containing the digest of the specified certificate.javaCert
- the Java X509Certificate to digestalgorithmURI
- digest algorithm URINoSuchAlgorithmException
- if the algorithm specified cannot be usedCertificateEncodingException
- if the certificate cannot be encodedpublic static void addPublicKey(@Nonnull KeyInfo keyInfo, @Nullable PublicKey pk)
KeyInfo
in a
new KeyValue
element.
As input, only supports PublicKey
s which are instances of either
DSAPublicKey
or RSAPublicKey
@Nonnull public static RSAKeyValue buildRSAKeyValue(@Nonnull RSAPublicKey rsaPubKey)
RSAKeyValue
XMLObject from the Java security RSA public key type.rsaPubKey
- a native Java RSAPublicKey
RSAKeyValue
XMLObject@Nonnull public static DSAKeyValue buildDSAKeyValue(@Nonnull DSAPublicKey dsaPubKey)
DSAKeyValue
XMLObject from the Java security DSA public key type.dsaPubKey
- a native Java DSAPublicKey
DSAKeyValue
XMLObjectpublic static void addDEREncodedPublicKey(@Nonnull KeyInfo keyInfo, @Nonnull PublicKey pk) throws NoSuchAlgorithmException, InvalidKeySpecException
KeyInfo
in a
new DEREncodedKeyValue
element.keyInfo
- the KeyInfo
element to which to add the keypk
- the native Java PublicKey
to convertNoSuchAlgorithmException
- if the key type is unsupportedInvalidKeySpecException
- if the key type does not support X.509 SPKI encoding@Nonnull public static List<PublicKey> getPublicKeys(@Nullable KeyInfo keyInfo) throws KeyException
keyInfo
- KeyInfo
to extract the keys out ofPublicKey
objectsKeyException
- thrown if the given key data can not be converted into PublicKey
@Nullable public static PublicKey getKey(@Nonnull KeyValue keyValue) throws KeyException
KeyValue
.keyValue
- the KeyValue
to extract the key fromKey
objectKeyException
- thrown if the given key data can not be converted into PublicKey
@Nonnull public static PublicKey getDSAKey(@Nonnull DSAKeyValue keyDescriptor) throws KeyException
DSAKeyValue
element. The element must contain values for all required DSA public
key parameters, including values for shared key family values P, Q and G.keyDescriptor
- the DSAKeyValue
key descriptorDSAPublicKey
instance of PublicKey
KeyException
- thrown if the key algorithm is not supported by the JCE or the key spec does not contain
valid information@Nonnull public static PublicKey getDSAKey(@Nonnull DSAKeyValue keyDescriptor, @Nonnull DSAParams dsaParams) throws KeyException
DSAKeyValue
element and the supplied Java DSAParams
, which supplies key
material from a shared key family.keyDescriptor
- the DSAKeyValue
key descriptordsaParams
- the DSAParams
DSA key family parametersDSAPublicKey
instance of PublicKey
KeyException
- thrown if the key algorithm is not supported by the JCE or the key spec does not contain
valid informationpublic static boolean hasCompleteDSAParams(@Nullable DSAKeyValue keyDescriptor)
DSAKeyValue
element has the all optional DSA values which can be shared
amongst many keys in a DSA "key family", and are presumed to be known from context.keyDescriptor
- the DSAKeyValue
element to check@Nonnull public static PublicKey getRSAKey(@Nonnull RSAKeyValue keyDescriptor) throws KeyException
RSAKeyValue
element.keyDescriptor
- the RSAKeyValue
key descriptorRSAPublicKey
instance of PublicKey
KeyException
- thrown if the key algorithm is not supported by the JCE or the key spec does not contain
valid information@Nonnull public static final BigInteger decodeBigIntegerFromCryptoBinary(@Nonnull String base64Value)
base64Value
- base64-encoded CryptoBinary value@Nonnull public static final String encodeCryptoBinaryFromBigInteger(@Nonnull BigInteger bigInt)
bigInt
- the BigInteger value@Nonnull protected static PublicKey buildKey(@Nonnull KeySpec keySpec, @Nonnull String keyAlgorithm) throws KeyException
keySpec
- KeySpec
specification for the keykeyAlgorithm
- key generation algorithm, only DSA and RSA supportedPublicKey
KeyException
- thrown if the key algorithm is not supported by the JCE or the key spec does not contain
valid information@Nonnull public static PublicKey getKey(@Nonnull DEREncodedKeyValue keyValue) throws KeyException
DEREncodedKeyValue
.keyValue
- the DEREncodedKeyValue
to extract the key fromKey
objectKeyException
- thrown if the given key data can not be converted into PublicKey
@Nonnull protected static CertificateFactory getX509CertFactory() throws CertificateException
CertificateFactory
the factory used to create X509 certificate objectsCertificateException
- thrown if the factory can not be created@Nullable public static KeyInfoGenerator getKeyInfoGenerator(@Nonnull Credential credential, @Nonnull NamedKeyInfoGeneratorManager manager, @Nullable String keyInfoProfileName)
KeyInfoGenerator
for the specified Credential
.
The KeyInfoGenerator returned is resolved via the supplied NamedKeyInfoGeneratorManager
and is determined by the type of the signing credential and an optional KeyInfo generator profile configuration
name. If the latter is ommited, the default manager (NamedKeyInfoGeneratorManager.getDefaultManager()
)
of the security configuration's named generator manager will be used.
credential
- the credential for which a generator is desiredmanager
- the NamedKeyInfoGeneratorManager instance to usekeyInfoProfileName
- the named KeyInfoGeneratorManager configuration to use (may be null)Copyright © 2016 JBoss by Red Hat. All rights reserved.