public final class AlgorithmSupport
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static org.slf4j.Logger |
LOG
Logger.
|
| Modifier | Constructor and Description |
|---|---|
private |
AlgorithmSupport()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkKeyAlgorithmAndLength(java.security.Key key,
AlgorithmDescriptor algorithm)
Check that the supplied key is consistent with the supplied algorithm's specified key algorithm and key length,
where applicable.
|
static boolean |
credentialSupportsAlgorithmForEncryption(Credential credential,
AlgorithmDescriptor algorithm)
Check whether the supplied credential may be used with the supplied algorithm for the purpose of
encryption.
|
static boolean |
credentialSupportsAlgorithmForSigning(Credential credential,
AlgorithmDescriptor algorithm)
Check whether the supplied credential may be used with the supplied algorithm for the purpose of
signing.
|
static java.security.KeyPair |
generateKeyPair(java.lang.String algoURI,
int keyLength)
Randomly generates a Java JCE KeyPair object from the specified XML Encryption algorithm URI.
|
static Credential |
generateKeyPairAndCredential(java.lang.String algorithmURI,
int keyLength,
boolean includePrivate)
Generate a random asymmetric key pair and return in a BasicCredential.
|
static javax.crypto.SecretKey |
generateSymmetricKey(java.lang.String algoURI)
Generates a random Java JCE symmetric Key object from the specified XML Encryption algorithm URI.
|
static Credential |
generateSymmetricKeyAndCredential(java.lang.String algorithmURI)
Generate a random symmetric key and return in a BasicCredential.
|
static java.lang.String |
getAlgorithmID(java.lang.String algorithmURI)
Get the Java security JCA/JCE algorithm identifier associated with an algorithm URI.
|
static AlgorithmRegistry |
getGlobalAlgorithmRegistry()
Get the global
AlgorithmRegistry instance. |
static java.lang.String |
getKeyAlgorithm(java.lang.String algorithmURI)
Get the Java security JCA/JCE key algorithm specifier associated with an algorithm URI.
|
static java.lang.Integer |
getKeyLength(java.lang.String algorithmURI)
Get the length of the key indicated by the algorithm URI, if applicable and available.
|
private static org.slf4j.Logger |
getLogger()
Get an SLF4J Logger.
|
static boolean |
isDataEncryptionAlgorithm(AlgorithmDescriptor algorithm)
Check whether the supplied descriptor represents an algorithm that my be used for
data encryption, i.e.
|
static boolean |
isHMAC(java.lang.String signatureAlgorithm)
Check whether the signature method algorithm URI indicates HMAC.
|
static boolean |
isKeyEncryptionAlgorithm(AlgorithmDescriptor algorithm)
Check whether the supplied descriptor represents an algorithm that my be used for
key encryption, i.e.
|
static boolean |
isRSAOAEP(java.lang.String keyTransportAlgorithm)
Check whether the key transport encryption algorithm URI indicates RSA-OAEP.
|
static boolean |
validateAlgorithmURI(java.lang.String algorithmURI,
java.util.Collection<java.lang.String> whitelistedAlgorithmURIs,
java.util.Collection<java.lang.String> blacklistedAlgorithmURIs)
Validate the supplied algorithm URI against the specified whitelist and blacklist.
|
@Nullable public static AlgorithmRegistry getGlobalAlgorithmRegistry()
AlgorithmRegistry instance.public static boolean isKeyEncryptionAlgorithm(@Nullable
AlgorithmDescriptor algorithm)
algorithm - the algorithm descriptor to evaluatepublic static boolean isDataEncryptionAlgorithm(@Nullable
AlgorithmDescriptor algorithm)
algorithm - the algorithm descriptor to evaluatepublic static boolean credentialSupportsAlgorithmForSigning(@Nullable
Credential credential,
@Nullable
AlgorithmDescriptor algorithm)
This checks the consistency of the type of credential signing key and the algorithm type, as well as the key algorithm and length where applicable.
credential - the candidate signing credential to evaluatealgorithm - the candidate signing algorithm to evaluatepublic static boolean credentialSupportsAlgorithmForEncryption(@Nullable
Credential credential,
@Nullable
AlgorithmDescriptor algorithm)
This checks the consistency of the extracted credential encryption key and the algorithm type, as well as the key algorithm and length where applicable.
credential - the candidate encryption credential to evaluatealgorithm - the candidate encryption algorithm to evaluatepublic static boolean checkKeyAlgorithmAndLength(@Nonnull
java.security.Key key,
@Nonnull
AlgorithmDescriptor algorithm)
key - the key to evaluatealgorithm - the algorithm to evaluate@Nullable
public static java.lang.String getAlgorithmID(@Nonnull
java.lang.String algorithmURI)
algorithmURI - the algorithm URI to evaluatepublic static boolean isRSAOAEP(@Nonnull
java.lang.String keyTransportAlgorithm)
keyTransportAlgorithm - the key transport encryption algorithm URIpublic static boolean isHMAC(@Nonnull
java.lang.String signatureAlgorithm)
signatureAlgorithm - the signature method algorithm URI@Nullable
public static java.lang.String getKeyAlgorithm(@Nonnull
java.lang.String algorithmURI)
algorithmURI - the algorithm URI to evaluate@Nullable
public static java.lang.Integer getKeyLength(@Nonnull
java.lang.String algorithmURI)
algorithmURI - the algorithm URI to evaluate@Nonnull
public static javax.crypto.SecretKey generateSymmetricKey(@Nonnull
java.lang.String algoURI)
throws java.security.NoSuchAlgorithmException,
java.security.KeyException
algoURI - The XML Encryption algorithm URIjava.security.NoSuchAlgorithmException - thrown if the specified algorithm is invalidjava.security.KeyException - thrown if the length of the key to generate could not be determined@Nonnull
public static java.security.KeyPair generateKeyPair(@Nonnull
java.lang.String algoURI,
int keyLength)
throws java.security.NoSuchAlgorithmException,
java.security.NoSuchProviderException
algoURI - The XML Encryption algorithm URIkeyLength - the length of key to generatejava.security.NoSuchProviderException - provider not foundjava.security.NoSuchAlgorithmException - algorithm not found@Nonnull public static Credential generateSymmetricKeyAndCredential(@Nonnull java.lang.String algorithmURI) throws java.security.NoSuchAlgorithmException, java.security.KeyException
algorithmURI - The XML Encryption algorithm URIjava.security.KeyExceptionjava.security.NoSuchAlgorithmException - algorithm not found@Nonnull public static Credential generateKeyPairAndCredential(@Nonnull java.lang.String algorithmURI, int keyLength, boolean includePrivate) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException
algorithmURI - The XML Encryption algorithm URIkeyLength - key lengthincludePrivate - if true, the private key will be included as welljava.security.NoSuchAlgorithmException - algorithm not foundjava.security.NoSuchProviderException - provider not foundpublic static boolean validateAlgorithmURI(@Nonnull
java.lang.String algorithmURI,
@Nullable
java.util.Collection<java.lang.String> whitelistedAlgorithmURIs,
@Nullable
java.util.Collection<java.lang.String> blacklistedAlgorithmURIs)
algorithmURI - the algorithm URI to evaluatewhitelistedAlgorithmURIs - the algorithm whitelistblacklistedAlgorithmURIs - the algorithm blacklist@Nonnull private static org.slf4j.Logger getLogger()