Object KeystoreHelper

  • All Implemented Interfaces:

    
    public class KeystoreHelper
    
                        

    Helper class to perform key management and signing operations.

    https://developer.android.com/training/articles/keystore

    • Constructor Detail

    • Method Detail

      • createKeyPair

         final PublicKey createKeyPair(String keyName, String algorithm, Integer purpose, Boolean authenticationRequired, Boolean invalidatedByBiometricEnrollment)

        Generates a private and public key to sign data. An existing key pair with the same alias will be deleted.

        <p> The key size is specific to provided algorithm and could be looked up from the algorithm-specific parameters via <a href="https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder.html#setAlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)">setAlgorithmParameterSpec</a>.
        Parameters:
        keyName - the unique identifier of the key pair
        algorithm - the standard string name of the algorithm to generate the key pair
        authenticationRequired - indicates whether the generated key requires authentication (fingerprint) in order to get access to it.
        invalidatedByBiometricEnrollment - indicates whether the key should be invalidated on biometric enrollment.
      • deleteKeyPair

         final Unit deleteKeyPair(String keyName)

        Delete a private and public key from the KeyStore.

        Parameters:
        keyName - the unique identifier of the key pair
      • exportPublicKey

         final String exportPublicKey(String keyName, Integer base64EncodingOption)

        Returns the public key retrieved from the keystore.

        Parameters:
        keyName - the unique identifier of the key pair
        base64EncodingOption - the encoding format of the public key
        Returns:

        String encoded representation of the key or null if any error

      • exists

         final Boolean exists(String keyName)

        Query the keystore for a matching key name.

        Parameters:
        keyName - the unique identifier of the key
        Returns:

        true if the key exists, false otherwise

      • getPrivateKey

        @Nullable() final PrivateKey getPrivateKey(String keyName)

        Query the Keystore for the private key.

        Parameters:
        keyName - the unique identifier of the key pair
        Returns:

        the private key or null if the key is not found