Search in sources :

Example 96 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec in project nhin-d by DirectProject.

the class AbstractPKCS11TokenKeyStoreProtectionManager method setPrivateKeyProtectionKeyAsString.

/**
	 * {@inheritDoc}
	 */
@Override
public void setPrivateKeyProtectionKeyAsString(String key) throws CryptoException {
    try {
        final Key keySpec = new SecretKeySpec(key.getBytes(), "");
        safeSetKeyWithRetry(privateKeyPassPhraseAlias, keySpec);
    } catch (CryptoException e) {
        throw e;
    } catch (Exception e) {
        throw new CryptoException("Error storing key store protection into PKCS11 token", e);
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) CryptoException(org.nhindirect.common.crypto.exceptions.CryptoException) Key(java.security.Key) SecretKey(javax.crypto.SecretKey) CryptoException(org.nhindirect.common.crypto.exceptions.CryptoException)

Example 97 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec in project nhin-d by DirectProject.

the class AbstractPKCS11TokenKeyStoreProtectionManager method setKeyStoreProtectionKeyAsBytes.

/**
	 * {@inheritDoc}
	 */
@Override
public void setKeyStoreProtectionKeyAsBytes(byte[] key) throws CryptoException {
    try {
        final Key keySpec = new SecretKeySpec(key, "");
        safeSetKeyWithRetry(keyStorePassPhraseAlias, keySpec);
    } catch (CryptoException e) {
        throw e;
    } catch (Exception e) {
        throw new CryptoException("Error storing key store protection into PKCS11 token", e);
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) CryptoException(org.nhindirect.common.crypto.exceptions.CryptoException) Key(java.security.Key) SecretKey(javax.crypto.SecretKey) CryptoException(org.nhindirect.common.crypto.exceptions.CryptoException)

Example 98 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec in project nhin-d by DirectProject.

the class BootstrappedKeyStoreProtectionManager method setPrivateKeyProtectionKey.

/**
	 * Sets the pass phrase that protects the private keys in the key store as a byte array.
	 * @param privateKeyProtectionKey The pass phrase that protects the private keys in the key store as a byte array.
	 */
public void setPrivateKeyProtectionKey(byte[] privateKeyProtectionKey) {
    this.privateKeyProtectionKey = new SecretKeySpec(privateKeyProtectionKey, "");
    keyEntries.put(PrivKeyProtKey, new SecretKeyEntry((SecretKey) this.privateKeyProtectionKey));
}
Also used : SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) SecretKeyEntry(java.security.KeyStore.SecretKeyEntry)

Example 99 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec in project nhin-d by DirectProject.

the class BootstrappedKeyStoreProtectionManager method setPrivateKeyProtectionKey.

/**
	 * Sets the pass phrase that protects the private keys in the key store as a String.
	 * @param privateKeyProtectionKey The pass phrase that protects the private keys in the key store as a String.
	 */
public void setPrivateKeyProtectionKey(String privateKeyProtectionKey) {
    this.privateKeyProtectionKey = new SecretKeySpec(privateKeyProtectionKey.getBytes(), "");
    keyEntries.put(PrivKeyProtKey, new SecretKeyEntry((SecretKey) this.privateKeyProtectionKey));
}
Also used : SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) SecretKeyEntry(java.security.KeyStore.SecretKeyEntry)

Example 100 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec in project nhin-d by DirectProject.

the class BootstrappedKeyStoreProtectionManager method setKeyStoreProtectionKey.

/**
	 * Sets the pass phrase that protects the key store as a whole as a byte array.
	 * @param keyStoreProtectionKey The pass phrase that protects the key store as a whole as a byte array.
	 */
public void setKeyStoreProtectionKey(byte[] keyStoreProtectionKey) {
    this.keyStoreProtectionKey = new SecretKeySpec(keyStoreProtectionKey, "");
    keyEntries.put(KeyStoreProtKey, new SecretKeyEntry((SecretKey) this.keyStoreProtectionKey));
}
Also used : SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) SecretKeyEntry(java.security.KeyStore.SecretKeyEntry)

Aggregations

SecretKeySpec (javax.crypto.spec.SecretKeySpec)432 Cipher (javax.crypto.Cipher)165 SecretKey (javax.crypto.SecretKey)128 Mac (javax.crypto.Mac)101 IvParameterSpec (javax.crypto.spec.IvParameterSpec)95 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)80 InvalidKeyException (java.security.InvalidKeyException)55 IOException (java.io.IOException)39 SecureRandom (java.security.SecureRandom)28 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 Key (java.security.Key)27 GeneralSecurityException (java.security.GeneralSecurityException)25 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)25 BadPaddingException (javax.crypto.BadPaddingException)23 MessageDigest (java.security.MessageDigest)22 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)21 Test (org.junit.Test)19 PrivateKey (java.security.PrivateKey)18 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)17 PublicKey (java.security.PublicKey)16