use of org.nhindirect.common.crypto.exceptions.CryptoException in project nhin-d by DirectProject.
the class AbstractPKCS11TokenKeyStoreProtectionManager method getAllEntries.
/**
* {@inheritDoc}
*/
@Override
public Map<String, Entry> getAllEntries() throws CryptoException {
final Map<String, Entry> entries = new HashMap<String, Entry>();
try {
final Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
final String alias = aliases.nextElement();
if (ks.isKeyEntry(alias)) {
try {
final Entry entry = ks.getEntry(alias, null);
entries.put(alias, entry);
} catch (Exception e) {
// no-op, this might be a key that we don't care about
}
}
}
} catch (Exception e) {
throw new CryptoException("Error extracting entries from PKCS11 token", e);
}
return entries;
}
use of org.nhindirect.common.crypto.exceptions.CryptoException in project nhin-d by DirectProject.
the class AbstractPKCS11TokenKeyStoreProtectionManager method unwrapWithSecretKey.
/**
* {@inheritDoc}}
*/
@Override
public Key unwrapWithSecretKey(SecretKey kek, byte[] wrappedData, String keyAlg, int keyType) throws CryptoException {
final IvParameterSpec iv = new IvParameterSpec(IV_BYTES);
try {
final Cipher unwrapCipher = Cipher.getInstance(WRAP_ALGO, ks.getProvider().getName());
unwrapCipher.init(Cipher.UNWRAP_MODE, kek, iv);
return unwrapCipher.unwrap(wrappedData, keyAlg, keyType);
} catch (Exception e) {
throw new CryptoException("Failed to unwrap key: " + e.getMessage(), e);
}
}
use of org.nhindirect.common.crypto.exceptions.CryptoException in project nhin-d by DirectProject.
the class BootstrappedKeyStoreProtectionManager method unwrapWithSecretKey.
/**
* {@inheritDoc}}
*/
@Override
public Key unwrapWithSecretKey(SecretKey kek, byte[] wrappedData, String keyAlg, int keyType) throws CryptoException {
final IvParameterSpec iv = new IvParameterSpec(AbstractPKCS11TokenKeyStoreProtectionManager.IV_BYTES);
try {
final Cipher unwrapCipher = Cipher.getInstance(AbstractPKCS11TokenKeyStoreProtectionManager.WRAP_ALGO);
unwrapCipher.init(Cipher.UNWRAP_MODE, kek, iv);
return unwrapCipher.unwrap(wrappedData, keyAlg, keyType);
} catch (Exception e) {
throw new CryptoException("Failed to unwrap key: " + e.getMessage(), e);
}
}
use of org.nhindirect.common.crypto.exceptions.CryptoException in project nhin-d by DirectProject.
the class BootstrappedKeyStoreProtectionManager method wrapWithSecretKey.
/**
* {@inheritDoc}}
*/
@Override
public byte[] wrapWithSecretKey(SecretKey kek, Key keyToWrap) throws CryptoException {
final IvParameterSpec iv = new IvParameterSpec(AbstractPKCS11TokenKeyStoreProtectionManager.IV_BYTES);
try {
final Cipher wrapCipher = Cipher.getInstance(AbstractPKCS11TokenKeyStoreProtectionManager.WRAP_ALGO);
wrapCipher.init(Cipher.WRAP_MODE, kek, iv);
return wrapCipher.wrap(keyToWrap);
} catch (Exception e) {
throw new CryptoException("Failed to wrap key: " + e.getMessage(), e);
}
}
use of org.nhindirect.common.crypto.exceptions.CryptoException in project nhin-d by DirectProject.
the class DynamicPKCS11TokenKeyStoreProtectionManager method initTokenStore.
/**
* {@inheritDocs}
*/
public void initTokenStore() throws CryptoException {
try {
loadProvider();
ks = keyStoreBuilder.getKeyStore();
ks.load(keyStoreSource, null);
} catch (Exception e) {
throw new CryptoException("Error initializing PKCS11 token", e);
}
}
Aggregations