// Path: lib/src/main/java/com/google/capillary/NoSuchKeyException.java
// public final class NoSuchKeyException extends CapillaryException {
// 
//   /**
//    * Creates a new {@link NoSuchKeyException} object.
//    *
//    * @param msg the exception message.
//    */
//   public NoSuchKeyException(String msg) {
//     super(msg);
//   }
// }
// 
// Path: lib/src/main/java/com/google/capillary/RsaEcdsaConstants.java
// public enum Padding {
//   OAEP("OAEPPadding"),
//   PKCS1("PKCS1Padding");
// 
//   private static final String PREFIX = "RSA/ECB/";
// 
//   private final String padding;
// 
//   Padding(String val) {
//     padding = val;
//   }
// 
//   /**
//    * Returns the current padding enum's transformation string that should be used when calling
//    * {@code javax.crypto.Cipher.getInstance}.
//    *
//    * @return the transformation string.
//    */
//   public String getTransformation() {
//     return PREFIX + padding;
//   }
// }


import android.content.Context;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.security.KeyPairGeneratorSpec;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import com.google.capillary.NoSuchKeyException;
import com.google.capillary.RsaEcdsaConstants.Padding;
import java.math.BigInteger;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.UnrecoverableKeyException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.RSAKeyGenParameterSpec;
import javax.security.auth.x500.X500Principal;
import org.joda.time.LocalDate;
      NoSuchKeyException {
    String alias = toKeyAlias(keychainId, isAuth);
    checkKeyExists(keyStore, alias);
    return (PrivateKey) keyStore.getKey(alias, null);
  }

  static void deleteKeyPair(KeyStore keyStore, String keychainId, boolean isAuth)
      throws NoSuchKeyException, KeyStoreException {
    String alias = toKeyAlias(keychainId, isAuth);
    checkKeyExists(keyStore, alias);
    keyStore.deleteEntry(alias);
  }

  private static String toKeyAlias(String keychainId, boolean isAuth) {
    String suffix = isAuth ? AUTH_KEY_ALIAS_SUFFIX : NO_AUTH_KEY_ALIAS_SUFFIX;
    return keychainId + suffix;
  }

  static void checkKeyExists(KeyStore keyStore, String keychainId, boolean isAuth)
      throws NoSuchKeyException, KeyStoreException {
    checkKeyExists(keyStore, toKeyAlias(keychainId, isAuth));
  }

  private static void checkKeyExists(KeyStore keyStore, String alias)
      throws NoSuchKeyException, KeyStoreException {
    if (!keyStore.containsAlias(alias)) {
      throw new NoSuchKeyException("android key store has no rsa key pair with alias " + alias);
    }
  }

// Path: lib/src/main/java/com/google/capillary/NoSuchKeyException.java
// public final class NoSuchKeyException extends CapillaryException {
// 
//   /**
//    * Creates a new {@link NoSuchKeyException} object.
//    *
//    * @param msg the exception message.
//    */
//   public NoSuchKeyException(String msg) {
//     super(msg);
//   }
// }
// 
// Path: lib/src/main/java/com/google/capillary/RsaEcdsaConstants.java
// public enum Padding {
//   OAEP("OAEPPadding"),
//   PKCS1("PKCS1Padding");
// 
//   private static final String PREFIX = "RSA/ECB/";
// 
//   private final String padding;
// 
//   Padding(String val) {
//     padding = val;
//   }
// 
//   /**
//    * Returns the current padding enum's transformation string that should be used when calling
//    * {@code javax.crypto.Cipher.getInstance}.
//    *
//    * @return the transformation string.
//    */
//   public String getTransformation() {
//     return PREFIX + padding;
//   }
// }


// Path: lib-android/src/main/java/com/google/capillary/android/AndroidKeyStoreRsaUtils.java
import android.content.Context;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.security.KeyPairGeneratorSpec;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import com.google.capillary.NoSuchKeyException;
import com.google.capillary.RsaEcdsaConstants.Padding;
import java.math.BigInteger;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.UnrecoverableKeyException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.RSAKeyGenParameterSpec;
import javax.security.auth.x500.X500Principal;
import org.joda.time.LocalDate;

      NoSuchKeyException {
    String alias = toKeyAlias(keychainId, isAuth);
    checkKeyExists(keyStore, alias);
    return (PrivateKey) keyStore.getKey(alias, null);
  }

  static void deleteKeyPair(KeyStore keyStore, String keychainId, boolean isAuth)
      throws NoSuchKeyException, KeyStoreException {
    String alias = toKeyAlias(keychainId, isAuth);
    checkKeyExists(keyStore, alias);
    keyStore.deleteEntry(alias);
  }

  private static String toKeyAlias(String keychainId, boolean isAuth) {
    String suffix = isAuth ? AUTH_KEY_ALIAS_SUFFIX : NO_AUTH_KEY_ALIAS_SUFFIX;
    return keychainId + suffix;
  }

  static void checkKeyExists(KeyStore keyStore, String keychainId, boolean isAuth)
      throws NoSuchKeyException, KeyStoreException {
    checkKeyExists(keyStore, toKeyAlias(keychainId, isAuth));
  }

  private static void checkKeyExists(KeyStore keyStore, String alias)
      throws NoSuchKeyException, KeyStoreException {
    if (!keyStore.containsAlias(alias)) {
      throw new NoSuchKeyException("android key store has no rsa key pair with alias " + alias);
    }
  }

  static Padding getCompatibleRsaPadding() {