Search in sources :

Example 6 with KeyStoreException

use of com.toshi.exception.KeyStoreException in project toshi-android-client by toshiapp.

the class KeystoreHandler23 method createNewKeysIfNeeded.

@Override
protected void createNewKeysIfNeeded() throws KeyStoreException {
    try {
        if (this.keyStore.containsAlias(this.alias))
            return;
        final KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, KeyStoreBase.ANDROID_KEY_STORE);
        keyGenerator.init(new KeyGenParameterSpec.Builder(this.alias, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT).setBlockModes(KeyProperties.BLOCK_MODE_GCM).setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE).setRandomizedEncryptionRequired(false).build());
        keyGenerator.generateKey();
    } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException | java.security.KeyStoreException e) {
        throw new KeyStoreException(new Throwable(e.getMessage()));
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) KeyGenParameterSpec(android.security.keystore.KeyGenParameterSpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(com.toshi.exception.KeyStoreException) NoSuchProviderException(java.security.NoSuchProviderException) KeyGenerator(javax.crypto.KeyGenerator)

Aggregations

KeyStoreException (com.toshi.exception.KeyStoreException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 KeyStoreHandler (com.toshi.crypto.keyStore.KeyStoreHandler)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvalidKeyException (java.security.InvalidKeyException)2 UnrecoverableEntryException (java.security.UnrecoverableEntryException)2 BadPaddingException (javax.crypto.BadPaddingException)2 Cipher (javax.crypto.Cipher)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 GCMParameterSpec (javax.crypto.spec.GCMParameterSpec)2 KeyGenParameterSpec (android.security.keystore.KeyGenParameterSpec)1 NonNull (android.support.annotation.NonNull)1 IOException (java.io.IOException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 CertificateException (java.security.cert.CertificateException)1 KeyGenerator (javax.crypto.KeyGenerator)1