whorlwind/src/main/java/com/squareup/whorlwind/RealWhorlwind.java
void prepareKeyStore() {
    try {
      Key key = keyStore.getKey(keyAlias, null);
      Certificate certificate = keyStore.getCertificate(keyAlias);
      if (key != null && certificate != null) {
        try {
          createCipher().init(Cipher.DECRYPT_MODE, key);

          // We have a keys in the store and they're still valid.
          return;
        } catch (KeyPermanentlyInvalidatedException e) {
          Log.d(TAG, "Key invalidated.");
        }
      }

      storage.clear();

      keyGenerator.initialize(new KeyGenParameterSpec.Builder(keyAlias,
          KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT) //
          .setBlockModes(KeyProperties.BLOCK_MODE_ECB) //
          .setUserAuthenticationRequired(true) //
          .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1) //
          .build());

      keyGenerator.generateKeyPair();
    } catch (GeneralSecurityException e) {
      throw new RuntimeException(e);
    }
  }
void prepareKeyStore() {
    try {
      Key key = keyStore.getKey(keyAlias, null);
      Certificate certificate = keyStore.getCertificate(keyAlias);
      if (key != null && certificate != null) {
        try {
          createCipher().init(Cipher.DECRYPT_MODE, key);

          // We have a keys in the store and they're still valid.
          return;
        } catch (KeyPermanentlyInvalidatedException e) {
          Log.d(TAG, "Key invalidated.");
        }
      }

      storage.clear();

      keyGenerator.initialize(new KeyGenParameterSpec.Builder(keyAlias,
          KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT) //
          .setBlockModes(KeyProperties.BLOCK_MODE_ECB) //
          .setUserAuthenticationRequired(true) //
          .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1) //
          .build());

      keyGenerator.generateKeyPair();
    } catch (GeneralSecurityException e) {
      throw new RuntimeException(e);
    }
  }
void prepareKeyStore ( ) { try { Key key = keyStore . getKey ( keyAlias , null ) ; Certificate certificate = keyStore . getCertificate ( keyAlias ) ; if ( key != null && certificate != null ) { try { createCipher ( ) . init ( Cipher . DECRYPT_MODE , key ) ; // We have a keys in the store and they're still valid. return ; } catch ( KeyPermanentlyInvalidatedException e ) { Log . d ( TAG , "Key invalidated." ) ; } } storage . clear ( ) ; keyGenerator . initialize ( new KeyGenParameterSpec . Builder ( keyAlias , KeyProperties . PURPOSE_ENCRYPT | KeyProperties . PURPOSE_DECRYPT ) // . setBlockModes ( KeyProperties . BLOCK_MODE_ECB ) // . setUserAuthenticationRequired ( true ) // . setEncryptionPaddings ( KeyProperties . ENCRYPTION_PADDING_RSA_PKCS1 ) // . build ( ) ) ; keyGenerator . generateKeyPair ( ) ; } catch ( GeneralSecurityException e ) { throw new RuntimeException ( e ) ; } }
Prepares the key store and our keys for encrypting/decrypting. Keys will be generated if we
haven't done so yet, and keys will be re-generated if the old ones have been invalidated. In
both cases, our K/V store will be cleared before continuing.
Prepares the key store and our keys for encrypting / decrypting . Keys will be generated if we haven t done so yet and keys will be re - generated if the old ones have been invalidated . In both cases our K / V store will be cleared before continuing .