public abstract class AbstractKeyPropertyType<T extends Key> extends DerivedFromSinglePropertyType<File,T>
PrivateKeyFilePropertyType
,
PublicKeyFilePropertyType
,
Serialized FormModifier and Type | Field and Description |
---|---|
static Class<PKCS8EncodedKeySpec> |
PKCS8_ENCODED_KEY_SPEC
The class of PKCS8EncodedKeySpec.
|
static Class<X509EncodedKeySpec> |
X509_ENCODED_KEY_SPEC
The class of X509EncodedKeySpec.
|
Constructor and Description |
---|
AbstractKeyPropertyType(String typeName,
Property<File> derivedFromType,
KeyFactoryAlgorithms algorithm,
Class<? extends EncodedKeySpec> encodedKeySpecClass)
Constructor.
|
AbstractKeyPropertyType(String typeName,
Property<File> derivedFromType,
KeyFactoryAlgorithms algorithm,
Class<? extends EncodedKeySpec> encodedKeySpecClass,
T defaultValue)
Constructor.
|
AbstractKeyPropertyType(String typeName,
Property<File> derivedFromType,
String algorithm,
Class<? extends EncodedKeySpec> encodedKeySpecClass)
Constructor.
|
AbstractKeyPropertyType(String typeName,
Property<File> derivedFromType,
String algorithm,
Class<? extends EncodedKeySpec> encodedKeySpecClass,
T defaultValue)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
String |
getAlgorithm()
Gets the algorithm to initialize the KeyFactory with.
|
Class<? extends EncodedKeySpec> |
getEncodedKeySpecClass()
The class which implements EncodedKeySpec.
|
protected EncodedKeySpec |
getEncodedKeySpecInstance(byte[] keyBytes)
Constructors an instance of EncodedKeySpecClass initialized with the bytes loaded from the file provided.
|
protected KeyFactory |
getKeyFactory()
Gets a KeyFactory instance on the base of the algorithm.
|
void |
validateConstraints(String propertyName)
Validates any constraints there are on a Key.
|
T |
validateDerivedValue(String propertyName)
Loads the Key from a file.
|
protected abstract T |
validateKey(EncodedKeySpec spec)
Validates the EncodedKeySpec to a ket of type T.
|
getDerivedFromProperty, getDerivedFromPropertyValue
getDerivedFrom, getDerivedFromCount, getDerivedFromProperty, getDerivedFromRestrictions, getDerivedToRestrictions, getMaxDerivedFrom, getMinDerivedFrom, getRestrictions, isMinAndMaxTheSame, isUseMaxDerivedFrom, isUseMinDerivedFrom, validateValue
equals, getDefaultValue, getDefaultValueAsString, getDefaultValueDescription, getDescription, getDescription, getInitializationPriority, getIo, getLogger, getTypeName, hasDefaultValue, isDefaultValueValid, postGetValueProcessing, setDefaultValue, setInitializationPriority, setIo, setTypedValue, setTypeName, toString, toType, validate, validateNullType
public static final Class<X509EncodedKeySpec> X509_ENCODED_KEY_SPEC
public static final Class<PKCS8EncodedKeySpec> PKCS8_ENCODED_KEY_SPEC
public AbstractKeyPropertyType(String typeName, Property<File> derivedFromType, String algorithm, Class<? extends EncodedKeySpec> encodedKeySpecClass) throws NullPointerException
typeName
- the type name string constant of File to KeyderivedFromType
- the property which points to the file where the key is stored.algorithm
- the name of the algortihm used.encodedKeySpecClass
- the class used to encoded the bytes.NullPointerException
- if any of the parameters is null
.EncodedKeySpec
,
X509EncodedKeySpec
,
PKCS8EncodedKeySpec
,
KeyFactory
,
KeyFactoryAlgorithms
public AbstractKeyPropertyType(String typeName, Property<File> derivedFromType, String algorithm, Class<? extends EncodedKeySpec> encodedKeySpecClass, T defaultValue) throws NullPointerException
typeName
- the type name string constant of File to KeyderivedFromType
- the property which points to the file where the key is stored.algorithm
- the name of the algortihm used.encodedKeySpecClass
- the class used to encoded the bytes.defaultValue
- NullPointerException
- if any of the parameters is null
.EncodedKeySpec
,
X509EncodedKeySpec
,
PKCS8EncodedKeySpec
,
KeyFactory
,
KeyFactoryAlgorithms
public AbstractKeyPropertyType(String typeName, Property<File> derivedFromType, KeyFactoryAlgorithms algorithm, Class<? extends EncodedKeySpec> encodedKeySpecClass) throws NullPointerException
typeName
- the type name string constant of File to KeyderivedFromType
- the property which points to the file where the key is stored.algorithm
- the name of the algortihm used.encodedKeySpecClass
- the class used to encoded the bytes.NullPointerException
- if any of the parameters is null
.EncodedKeySpec
,
X509EncodedKeySpec
,
PKCS8EncodedKeySpec
,
KeyFactory
,
KeyFactoryAlgorithms
public AbstractKeyPropertyType(String typeName, Property<File> derivedFromType, KeyFactoryAlgorithms algorithm, Class<? extends EncodedKeySpec> encodedKeySpecClass, T defaultValue) throws NullPointerException
typeName
- the type name string constant of File to KeyderivedFromType
- the property which points to the file where the key is stored.algorithm
- the name of the algortihm used.encodedKeySpecClass
- the class used to encoded the bytes.defaultValue
- the default key valueNullPointerException
- if any of the parameters is null
.EncodedKeySpec
,
X509EncodedKeySpec
,
PKCS8EncodedKeySpec
,
KeyFactory
,
KeyFactoryAlgorithms
public final String getAlgorithm()
public final Class<? extends EncodedKeySpec> getEncodedKeySpecClass()
EncodedKeySpec
,
X509EncodedKeySpec
,
PKCS8EncodedKeySpec
protected abstract T validateKey(EncodedKeySpec spec) throws PropertyException
spec
- an instance of EncodedKeySpec, which can be used with the KeyFactory to generate a Key.PropertyException
- the key could not be converted and/or validated to type T of key.public final T validateDerivedValue(String propertyName) throws PropertyException
fis = new FileInputStream(obj); dis = new DataInputStream(fis); byte[] keyBytes = new byte[(int) obj.length()]; dis.readFully(keyBytes); EncodedKeySpec encodedKeySpec = getEncodedKeySpecInstance(keyBytes); return validateKey(encodedKeySpec);
validateDerivedValue
in class DerivedPropertyType<T extends Key>
propertyName
- the name of derived PropertyPropertyException
- if it could not be converted into type T.protected final EncodedKeySpec getEncodedKeySpecInstance(byte[] keyBytes) throws PropertyException
keyBytes
- the bytes loaded from the file.PropertyException
- if their could not be made a instance of the classgetEncodedKeySpecClass()
public void validateConstraints(String propertyName) throws PropertyException
validateConstraints
in class DerivedPropertyType<T extends Key>
propertyName
- the name of the property used for logging purposes, to
identify the unique property which PropertyType has constraint
issues.PropertyException
- if the constraints have invalid/conflicting values.Property.validate()
protected final KeyFactory getKeyFactory() throws PropertyException
PropertyException
- if an the "algorithm" is null
or empty, or is not found.getAlgorithm()