public class KeyInfoSupport
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.security.cert.CertificateFactory |
x509CertFactory
Factory for
X509Certificate and X509CRL creation. |
| Modifier | Constructor and Description |
|---|---|
protected |
KeyInfoSupport()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addCertificate(KeyInfo keyInfo,
java.security.cert.X509Certificate cert)
|
static void |
addCRL(KeyInfo keyInfo,
java.security.cert.X509CRL crl)
|
static void |
addDEREncodedPublicKey(KeyInfo keyInfo,
java.security.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,
java.lang.String keyNameValue)
Add a new
KeyName value to a KeyInfo. |
static void |
addPublicKey(KeyInfo keyInfo,
java.security.PublicKey pk)
|
static DSAKeyValue |
buildDSAKeyValue(java.security.interfaces.DSAPublicKey dsaPubKey)
Builds a
DSAKeyValue XMLObject from the Java security DSA public key type. |
protected static java.security.PublicKey |
buildKey(java.security.spec.KeySpec keySpec,
java.lang.String keyAlgorithm)
Generates a public key from the given key spec.
|
static RSAKeyValue |
buildRSAKeyValue(java.security.interfaces.RSAPublicKey rsaPubKey)
Builds an
RSAKeyValue XMLObject from the Java security RSA public key type. |
static X509Certificate |
buildX509Certificate(java.security.cert.X509Certificate cert)
Builds an
X509Certificate XMLObject from a native Java
X509Certificate. |
static X509CRL |
buildX509CRL(java.security.cert.X509CRL crl)
Builds an
X509CRL XMLObject from a native Java
X509CRL. |
static X509Digest |
buildX509Digest(java.security.cert.X509Certificate javaCert,
java.lang.String algorithmURI)
Build an
X509Digest containing the digest of the specified certificate. |
static X509IssuerSerial |
buildX509IssuerSerial(java.lang.String issuerName,
java.math.BigInteger serialNumber)
Build an
X509IssuerSerial containing a given issuer name and serial number. |
static X509SKI |
buildX509SKI(java.security.cert.X509Certificate javaCert)
Build an
X509SKI containing the subject key identifier extension value contained within a certificate. |
static X509SubjectName |
buildX509SubjectName(java.lang.String subjectName)
Build an
X509SubjectName containing a given subject name. |
static java.math.BigInteger |
decodeBigIntegerFromCryptoBinary(java.lang.String base64Value)
Decode a base64-encoded ds:CryptoBinary value to a native Java BigInteger type.
|
static java.lang.String |
encodeCryptoBinaryFromBigInteger(java.math.BigInteger bigInt)
Encode a native Java BigInteger type to a base64-encoded ds:CryptoBinary value.
|
static java.security.cert.X509Certificate |
getCertificate(X509Certificate xmlCert)
Convert an
X509Certificate into a native Java representation. |
static java.util.List<java.security.cert.X509Certificate> |
getCertificates(KeyInfo keyInfo)
Get a list of the Java
X509Certificate within the given KeyInfo. |
static java.util.List<java.security.cert.X509Certificate> |
getCertificates(X509Data x509Data)
Get a list of the Java
X509Certificate within the given X509Data. |
static java.security.cert.X509CRL |
getCRL(X509CRL xmlCRL)
Convert an
X509CRL into a native Java representation. |
static java.util.List<java.security.cert.X509CRL> |
getCRLs(KeyInfo keyInfo)
Get a list of the Java
X509CRLs within the given KeyInfo. |
static java.util.List<java.security.cert.X509CRL> |
getCRLs(X509Data x509Data)
Get a list of the Java
X509CRLs within the given X509Data. |
static java.security.PublicKey |
getDSAKey(DSAKeyValue keyDescriptor)
Builds an DSA key from a
DSAKeyValue element. |
static java.security.PublicKey |
getDSAKey(DSAKeyValue keyDescriptor,
java.security.interfaces.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 java.security.PublicKey |
getKey(DEREncodedKeyValue keyValue)
Extracts the public key within the
DEREncodedKeyValue. |
static java.security.PublicKey |
getKey(KeyValue keyValue)
Extracts the DSA or RSA public key within the
KeyValue. |
static KeyInfoGenerator |
getKeyInfoGenerator(Credential credential,
NamedKeyInfoGeneratorManager manager,
java.lang.String keyInfoProfileName)
Obtains a
KeyInfoGenerator for the specified Credential. |
static java.util.List<java.lang.String> |
getKeyNames(KeyInfo keyInfo)
Get the set of key names inside the specified
KeyInfo as a list of strings. |
private static org.slf4j.Logger |
getLogger()
Get an SLF4J Logger.
|
static java.util.List<java.security.PublicKey> |
getPublicKeys(KeyInfo keyInfo)
|
static java.security.PublicKey |
getRSAKey(RSAKeyValue keyDescriptor)
Builds an RSA key from an
RSAKeyValue element. |
protected static java.security.cert.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. |
private static java.security.cert.CertificateFactory x509CertFactory
X509Certificate and X509CRL creation.@Nonnull
public static java.util.List<java.lang.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
java.lang.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 java.util.List<java.security.cert.X509Certificate> getCertificates(@Nullable
KeyInfo keyInfo)
throws java.security.cert.CertificateException
X509Certificate within the given KeyInfo.keyInfo - key info to extract the certificates fromX509Certificatesjava.security.cert.CertificateException - thrown if there is a problem converting the X509 data into
X509Certificates.@Nonnull
public static java.util.List<java.security.cert.X509Certificate> getCertificates(@Nullable
X509Data x509Data)
throws java.security.cert.CertificateException
X509Certificate within the given X509Data.x509Data - X509Data from which to extract the certificateX509Certificatesjava.security.cert.CertificateException - thrown if there is a problem converting the X509 data into
X509Certificates.@Nullable
public static java.security.cert.X509Certificate getCertificate(@Nullable
X509Certificate xmlCert)
throws java.security.cert.CertificateException
X509Certificate into a native Java representation.xmlCert - an X509CertificateX509Certificatejava.security.cert.CertificateException - thrown if there is a problem converting the X509 data into
X509Certificates.@Nonnull
public static java.util.List<java.security.cert.X509CRL> getCRLs(@Nullable
KeyInfo keyInfo)
throws java.security.cert.CRLException
X509CRLs within the given KeyInfo.keyInfo - the KeyInfo to extract the CRLs fromX509CRLsjava.security.cert.CRLException - thrown if there is a problem converting the CRL data into X509CRL
s@Nonnull
public static java.util.List<java.security.cert.X509CRL> getCRLs(@Nullable
X509Data x509Data)
throws java.security.cert.CRLException
X509CRLs within the given X509Data.x509Data - X509Data to extract the CRLs fromX509CRLsjava.security.cert.CRLException - thrown if there is a problem converting the CRL data into X509CRL
s@Nullable
public static java.security.cert.X509CRL getCRL(@Nullable
X509CRL xmlCRL)
throws java.security.cert.CRLException
X509CRL into a native Java representation.xmlCRL - object to extract the CRL fromX509CRL objectjava.security.cert.CRLException - thrown if there is a problem converting the CRL data into X509CRLpublic static void addCertificate(@Nonnull
KeyInfo keyInfo,
@Nonnull
java.security.cert.X509Certificate cert)
throws java.security.cert.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 addjava.security.cert.CertificateEncodingException - thrown when there is an error converting the Java certificate representation
to the XMLObject representationpublic static void addCRL(@Nonnull
KeyInfo keyInfo,
@Nonnull
java.security.cert.X509CRL crl)
throws java.security.cert.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 addjava.security.cert.CRLException - thrown when there is an error converting the Java CRL representation to the XMLObject
representation@Nonnull public static X509Certificate buildX509Certificate(java.security.cert.X509Certificate cert) throws java.security.cert.CertificateEncodingException
X509Certificate XMLObject from a native Java
X509Certificate.cert - the Java X509Certificate to convertX509Certificate XMLObjectjava.security.cert.CertificateEncodingException - thrown when there is an error converting the Java certificate representation
to the XMLObject representation@Nonnull public static X509CRL buildX509CRL(java.security.cert.X509CRL crl) throws java.security.cert.CRLException
X509CRL XMLObject from a native Java
X509CRL.crl - the Java X509CRL to convertX509CRL XMLObjectjava.security.cert.CRLException - thrown when there is an error converting the Java CRL representation to the XMLObject
representation@Nonnull public static X509SubjectName buildX509SubjectName(@Nullable java.lang.String subjectName)
X509SubjectName containing a given subject name.subjectName - the name content@Nonnull public static X509IssuerSerial buildX509IssuerSerial(@Nullable java.lang.String issuerName, @Nullable java.math.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 java.security.cert.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 java.security.cert.X509Certificate javaCert, @Nonnull java.lang.String algorithmURI) throws java.security.NoSuchAlgorithmException, java.security.cert.CertificateEncodingException
X509Digest containing the digest of the specified certificate.javaCert - the Java X509Certificate to digestalgorithmURI - digest algorithm URIjava.security.NoSuchAlgorithmException - if the algorithm specified cannot be usedjava.security.cert.CertificateEncodingException - if the certificate cannot be encodedpublic static void addPublicKey(@Nonnull
KeyInfo keyInfo,
@Nullable
java.security.PublicKey pk)
KeyInfo in a
new KeyValue element.
As input, only supports PublicKeys which are instances of either
DSAPublicKey or RSAPublicKeykeyInfo - the KeyInfo element to which to add the keypk - the native Java PublicKey to add@Nonnull public static RSAKeyValue buildRSAKeyValue(@Nonnull java.security.interfaces.RSAPublicKey rsaPubKey)
RSAKeyValue XMLObject from the Java security RSA public key type.rsaPubKey - a native Java RSAPublicKeyRSAKeyValue XMLObject@Nonnull public static DSAKeyValue buildDSAKeyValue(@Nonnull java.security.interfaces.DSAPublicKey dsaPubKey)
DSAKeyValue XMLObject from the Java security DSA public key type.dsaPubKey - a native Java DSAPublicKeyDSAKeyValue XMLObjectpublic static void addDEREncodedPublicKey(@Nonnull
KeyInfo keyInfo,
@Nonnull
java.security.PublicKey pk)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
KeyInfo in a
new DEREncodedKeyValue element.keyInfo - the KeyInfo element to which to add the keypk - the native Java PublicKey to convertjava.security.NoSuchAlgorithmException - if the key type is unsupportedjava.security.spec.InvalidKeySpecException - if the key type does not support X.509 SPKI encoding@Nonnull
public static java.util.List<java.security.PublicKey> getPublicKeys(@Nullable
KeyInfo keyInfo)
throws java.security.KeyException
keyInfo - KeyInfo to extract the keys out ofPublicKey objectsjava.security.KeyException - thrown if the given key data can not be converted into PublicKey@Nullable
public static java.security.PublicKey getKey(@Nonnull
KeyValue keyValue)
throws java.security.KeyException
KeyValue.keyValue - the KeyValue to extract the key fromKey objectjava.security.KeyException - thrown if the given key data can not be converted into PublicKey@Nonnull
public static java.security.PublicKey getDSAKey(@Nonnull
DSAKeyValue keyDescriptor)
throws java.security.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 PublicKeyjava.security.KeyException - thrown if the key algorithm is not supported by the JCE or the key spec does not contain
valid information@Nonnull
public static java.security.PublicKey getDSAKey(@Nonnull
DSAKeyValue keyDescriptor,
@Nonnull
java.security.interfaces.DSAParams dsaParams)
throws java.security.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 PublicKeyjava.security.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 java.security.PublicKey getRSAKey(@Nonnull
RSAKeyValue keyDescriptor)
throws java.security.KeyException
RSAKeyValue element.keyDescriptor - the RSAKeyValue key descriptorRSAPublicKey instance of PublicKeyjava.security.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 java.math.BigInteger decodeBigIntegerFromCryptoBinary(@Nonnull
java.lang.String base64Value)
base64Value - base64-encoded CryptoBinary value@Nonnull
public static final java.lang.String encodeCryptoBinaryFromBigInteger(@Nonnull
java.math.BigInteger bigInt)
bigInt - the BigInteger value@Nonnull
protected static java.security.PublicKey buildKey(@Nonnull
java.security.spec.KeySpec keySpec,
@Nonnull
java.lang.String keyAlgorithm)
throws java.security.KeyException
keySpec - KeySpec specification for the keykeyAlgorithm - key generation algorithm, only DSA and RSA supportedPublicKeyjava.security.KeyException - thrown if the key algorithm is not supported by the JCE or the key spec does not contain
valid information@Nonnull
public static java.security.PublicKey getKey(@Nonnull
DEREncodedKeyValue keyValue)
throws java.security.KeyException
DEREncodedKeyValue.keyValue - the DEREncodedKeyValue to extract the key fromKey objectjava.security.KeyException - thrown if the given key data can not be converted into PublicKey@Nonnull
protected static java.security.cert.CertificateFactory getX509CertFactory()
throws java.security.cert.CertificateException
CertificateFactory the factory used to create X509 certificate objectsjava.security.cert.CertificateException - thrown if the factory can not be created@Nullable public static KeyInfoGenerator getKeyInfoGenerator(@Nonnull Credential credential, @Nonnull NamedKeyInfoGeneratorManager manager, @Nullable java.lang.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)@Nonnull private static org.slf4j.Logger getLogger()