Search in sources :

Example 1 with SecretKeyEntry

use of java.security.KeyStore.SecretKeyEntry in project platform_frameworks_base by android.

the class AndroidKeyStoreSpi method engineSetEntry.

@Override
public void engineSetEntry(String alias, Entry entry, ProtectionParameter param) throws KeyStoreException {
    if (entry == null) {
        throw new KeyStoreException("entry == null");
    }
    Credentials.deleteAllTypesForAlias(mKeyStore, alias, mUid);
    if (entry instanceof java.security.KeyStore.TrustedCertificateEntry) {
        java.security.KeyStore.TrustedCertificateEntry trE = (java.security.KeyStore.TrustedCertificateEntry) entry;
        engineSetCertificateEntry(alias, trE.getTrustedCertificate());
        return;
    }
    if (entry instanceof PrivateKeyEntry) {
        PrivateKeyEntry prE = (PrivateKeyEntry) entry;
        setPrivateKeyEntry(alias, prE.getPrivateKey(), prE.getCertificateChain(), param);
    } else if (entry instanceof SecretKeyEntry) {
        SecretKeyEntry secE = (SecretKeyEntry) entry;
        setSecretKeyEntry(alias, secE.getSecretKey(), param);
    } else {
        throw new KeyStoreException("Entry must be a PrivateKeyEntry, SecretKeyEntry or TrustedCertificateEntry" + "; was " + entry);
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) SecretKeyEntry(java.security.KeyStore.SecretKeyEntry) KeyStore(android.security.KeyStore) PrivateKeyEntry(java.security.KeyStore.PrivateKeyEntry)

Example 2 with SecretKeyEntry

use of java.security.KeyStore.SecretKeyEntry 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 3 with SecretKeyEntry

use of java.security.KeyStore.SecretKeyEntry 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 4 with SecretKeyEntry

use of java.security.KeyStore.SecretKeyEntry 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)

Example 5 with SecretKeyEntry

use of java.security.KeyStore.SecretKeyEntry in project android_frameworks_base by DirtyUnicorns.

the class AndroidKeyStoreSpi method engineSetEntry.

@Override
public void engineSetEntry(String alias, Entry entry, ProtectionParameter param) throws KeyStoreException {
    if (entry == null) {
        throw new KeyStoreException("entry == null");
    }
    Credentials.deleteAllTypesForAlias(mKeyStore, alias, mUid);
    if (entry instanceof java.security.KeyStore.TrustedCertificateEntry) {
        java.security.KeyStore.TrustedCertificateEntry trE = (java.security.KeyStore.TrustedCertificateEntry) entry;
        engineSetCertificateEntry(alias, trE.getTrustedCertificate());
        return;
    }
    if (entry instanceof PrivateKeyEntry) {
        PrivateKeyEntry prE = (PrivateKeyEntry) entry;
        setPrivateKeyEntry(alias, prE.getPrivateKey(), prE.getCertificateChain(), param);
    } else if (entry instanceof SecretKeyEntry) {
        SecretKeyEntry secE = (SecretKeyEntry) entry;
        setSecretKeyEntry(alias, secE.getSecretKey(), param);
    } else {
        throw new KeyStoreException("Entry must be a PrivateKeyEntry, SecretKeyEntry or TrustedCertificateEntry" + "; was " + entry);
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) SecretKeyEntry(java.security.KeyStore.SecretKeyEntry) KeyStore(android.security.KeyStore) PrivateKeyEntry(java.security.KeyStore.PrivateKeyEntry)

Aggregations

SecretKeyEntry (java.security.KeyStore.SecretKeyEntry)12 KeyStoreException (java.security.KeyStoreException)7 SecretKey (javax.crypto.SecretKey)6 KeyStore (android.security.KeyStore)5 PrivateKeyEntry (java.security.KeyStore.PrivateKeyEntry)5 SecretKeySpec (javax.crypto.spec.SecretKeySpec)5 KeyStore (java.security.KeyStore)2 Entry (java.security.KeyStore.Entry)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 Protector (com.evolveum.midpoint.prism.crypto.Protector)1 ProtectorImpl (com.evolveum.midpoint.prism.crypto.ProtectorImpl)1 IOException (java.io.IOException)1 ProtectionParameter (java.security.KeyStore.ProtectionParameter)1 TrustedCertificateEntry (java.security.KeyStore.TrustedCertificateEntry)1 Provider (java.security.Provider)1 UnrecoverableEntryException (java.security.UnrecoverableEntryException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1