public abstract class AbstractPKCS11TokenKeyStoreProtectionManager extends Object implements MutableKeyStoreProtectionManager, WrappableKeyProtectionManager
For key wrapping, this class utilizes the AES/CBC/PKCS5Padding algorithm with a static initialization vector.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_KESTORE_TYPE |
static byte[] |
IV_BYTES |
static String |
SUNPKCS11_KEYSTORE_PROVIDER_NAME |
static String |
WRAP_ALGO |
| Constructor and Description |
|---|
AbstractPKCS11TokenKeyStoreProtectionManager()
Empty constructor.
|
AbstractPKCS11TokenKeyStoreProtectionManager(PKCS11Credential credential,
String keyStorePassPhraseAlias,
String privateKeyPassPhraseAlias)
Constructor that takes a credential interface for logging into the token.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearEntry(String alias)
Generic method to clear an arbitrary entry.
|
void |
clearKey(String alias)
Generic method to clear an arbitrary key.
|
void |
clearKeyStoreProtectionKey()
Clears the key use to protect the key store.
|
void |
clearPrivateKeyProtectionKey()
Clears the key use to protect the private key.
|
Map<String,KeyStore.Entry> |
getAllEntries()
Gets a Map of all entries managed by the token.
|
Map<String,Key> |
getAllKeys()
Gets a Map of all keys managed by the token.
|
KeyStore.Entry |
getEntry(String entryName)
Gets a specific entry by name
|
Key |
getKey(String keyName)
Gets a specific key by name.
|
Key |
getKeyStoreProtectionKey()
Gets the key protecting private keys in the key store.
|
KeyStore |
getKS()
Gets the underlying KeyStore object.
|
Key |
getPrivateKeyProtectionKey()
Gets the key protecting the key store as a whole.
|
abstract void |
initTokenStore()
Initializes access to the token.
|
void |
setCredential(PKCS11Credential credential)
Sets the credential used to log into the token.
|
void |
setEntry(String alias,
KeyStore.Entry entry)
Generic method to set an arbitrary entry.
|
void |
setKey(String alias,
Key key)
Generic method to set an arbitrary key.
|
void |
setKeyStorePassPhraseAlias(String keyStorePassPhraseAlias)
Sets the alias name of the key store key in the PKCS11 token.
|
void |
setKeyStoreProtectionKey(Key key)
Sets key used to protect the key store as a Key object.
|
void |
setKeyStoreProtectionKeyAsBytes(byte[] key)
Sets key used to protect the key store as a byte array.
|
void |
setKeyStoreProtectionKeyAsString(String key)
Sets key used to protect the key store as a string.
|
void |
setKeyStoreProviderName(String keyStoreProviderName) |
void |
setKeyStoreSource(InputStream keyStoreSource) |
void |
setKeyStoreSourceAsString(String keyStoreSource) |
void |
setKeyStoreType(String keyStoreType) |
void |
setPcks11ConfigFile(String pcks11ConfigFile) |
void |
setPrivateKeyPassPhraseAlias(String privateKeyPassPhraseAlias)
Sets the alias name of the private key protection key in the PKCS11 token.
|
void |
setPrivateKeyProtectionKey(Key key)
Sets key used to protect the private key as a Key object.
|
void |
setPrivateKeyProtectionKeyAsBytes(byte[] key)
Sets the key used to protect the private key as a byte array.
|
void |
setPrivateKeyProtectionKeyAsString(String key)
Sets the key used to protect the private key as a string.
|
Key |
unwrapWithSecretKey(SecretKey kek,
byte[] wrappedData,
String keyAlg,
int keyType)
Unwraps the key with a symmetric secret key encryption key.
|
byte[] |
wrapWithSecretKey(SecretKey kek,
Key keyToWrap)
Wraps a key with a symmetric secret key encryption key.
|
public static final String SUNPKCS11_KEYSTORE_PROVIDER_NAME
public static final String DEFAULT_KESTORE_TYPE
public static final String WRAP_ALGO
public static final byte[] IV_BYTES
public AbstractPKCS11TokenKeyStoreProtectionManager()
throws CryptoException
CryptoExceptionpublic AbstractPKCS11TokenKeyStoreProtectionManager(PKCS11Credential credential, String keyStorePassPhraseAlias, String privateKeyPassPhraseAlias) throws CryptoException
credential - The credential used to log into the token.keyStorePassPhraseAlias - The alias name of the key store key in the PKCS11 token.privateKeyPassPhraseAlias - The alias name of the private key protection key in the PKCS11 token.CryptoExceptionpublic void setCredential(PKCS11Credential credential)
credential - The credential used to log into the token.public void setKeyStorePassPhraseAlias(String keyStorePassPhraseAlias)
keyStorePassPhraseAlias - The alias name of the key store key in the PKCS11 token.public void setPrivateKeyPassPhraseAlias(String privateKeyPassPhraseAlias)
privateKeyPassPhraseAlias - the alias name of the private key protection key in the PKCS11 token.public void setKeyStoreType(String keyStoreType)
public void setKeyStoreSource(InputStream keyStoreSource)
public void setKeyStoreSourceAsString(String keyStoreSource)
public void setKeyStoreProviderName(String keyStoreProviderName)
public void setPcks11ConfigFile(String pcks11ConfigFile)
public abstract void initTokenStore()
throws CryptoException
CryptoExceptionpublic Map<String,Key> getAllKeys() throws CryptoException
getAllKeys in interface KeyStoreProtectionManagerCryptoExceptionpublic Key getKey(String keyName) throws CryptoException
getKey in interface KeyStoreProtectionManagerkeyName - The name of the key to retrieve. Returns null if the key doesn't exist.CryptoExceptionpublic Key getPrivateKeyProtectionKey() throws CryptoException
getPrivateKeyProtectionKey in interface KeyStoreProtectionManagerCryptoExceptionpublic Key getKeyStoreProtectionKey() throws CryptoException
getKeyStoreProtectionKey in interface KeyStoreProtectionManagerCryptoExceptionpublic Map<String,KeyStore.Entry> getAllEntries() throws CryptoException
getAllEntries in interface KeyStoreProtectionManagerCryptoExceptionpublic KeyStore.Entry getEntry(String entryName) throws CryptoException
getEntry in interface KeyStoreProtectionManagerentryName - The name of the entry to retrieve. Returns null if the entry doesn't exist.CryptoExceptionpublic void setPrivateKeyProtectionKey(Key key) throws CryptoException
setPrivateKeyProtectionKey in interface MutableKeyStoreProtectionManagerkey - The key used to protect private keys.CryptoExceptionpublic void setPrivateKeyProtectionKeyAsBytes(byte[] key)
throws CryptoException
setPrivateKeyProtectionKeyAsBytes in interface MutableKeyStoreProtectionManagerkey - The key used to protect private keys.CryptoExceptionpublic void setPrivateKeyProtectionKeyAsString(String key) throws CryptoException
setPrivateKeyProtectionKeyAsString in interface MutableKeyStoreProtectionManagerkey - The key used to protect private keys.CryptoExceptionpublic void clearPrivateKeyProtectionKey()
throws CryptoException
clearPrivateKeyProtectionKey in interface MutableKeyStoreProtectionManagerCryptoExceptionpublic void setKeyStoreProtectionKey(Key key) throws CryptoException
setKeyStoreProtectionKey in interface MutableKeyStoreProtectionManagerkey - The key used to protect the key store.CryptoExceptionpublic void setKeyStoreProtectionKeyAsBytes(byte[] key)
throws CryptoException
setKeyStoreProtectionKeyAsBytes in interface MutableKeyStoreProtectionManagerkey - The key used to protect the key store.CryptoExceptionpublic void setKeyStoreProtectionKeyAsString(String key) throws CryptoException
setKeyStoreProtectionKeyAsString in interface MutableKeyStoreProtectionManagerkey - The key used to protect the key store.CryptoExceptionpublic void clearKeyStoreProtectionKey()
throws CryptoException
clearKeyStoreProtectionKey in interface MutableKeyStoreProtectionManagerCryptoExceptionpublic void setKey(String alias, Key key) throws CryptoException
setKey in interface MutableKeyStoreProtectionManageralias - Alias of the key that will be set.key - The key that will be set.CryptoExceptionpublic void clearKey(String alias) throws CryptoException
clearKey in interface MutableKeyStoreProtectionManageralias - Alias of the key that will be cleared.CryptoExceptionpublic void setEntry(String alias, KeyStore.Entry entry) throws CryptoException
setEntry in interface MutableKeyStoreProtectionManageralias - Alias of the entry that will be set.entry - The entry that will be set.CryptoExceptionpublic void clearEntry(String alias) throws CryptoException
clearEntry in interface MutableKeyStoreProtectionManageralias - Alias of the entry that will be cleared.CryptoExceptionpublic KeyStore getKS()
getKS in interface MutableKeyStoreProtectionManagerpublic byte[] wrapWithSecretKey(SecretKey kek, Key keyToWrap) throws CryptoException
wrapWithSecretKey in interface WrappableKeyProtectionManagerkek - The key encryption key.keyToWrap - The key to be wrapped.CryptoExceptionpublic Key unwrapWithSecretKey(SecretKey kek, byte[] wrappedData, String keyAlg, int keyType) throws CryptoException
unwrapWithSecretKey in interface WrappableKeyProtectionManagerkek - The key encryption key.wrappedData - The wrapped key as a byte array.keyAlg - The algorithm of the key that is being decrypted. Typical parameters are "RSA", "DSA", and "AES" depending on the key type.keyType - The type of key that is wrapped. Valid values should use the Cipher.PRIVATE_KEY and Cipher.SECRET_KEY constants.CryptoExceptionCopyright © 2010–2021 The Direct Project. All rights reserved.