Package com.ibm.security.verifysdk.core
Object KeystoreHelper
-
- All Implemented Interfaces:
public class KeystoreHelper
Helper class to perform key management and signing operations.
https://developer.android.com/training/articles/keystore
-
-
Field Summary
Fields Modifier and Type Field Description private String
keystoreType
private Integer
keySize
private final ArrayList<String>
supportedAlgorithms
public final static KeystoreHelper
INSTANCE
-
Method Summary
Modifier and Type Method Description final PublicKey
createKeyPair(String keyName, String algorithm, Integer purpose, Boolean authenticationRequired, Boolean invalidatedByBiometricEnrollment)
Generates a private and public key to sign data. final Unit
deleteKeyPair(String keyName)
Delete a private and public key from the KeyStore. final String
exportPublicKey(String keyName, Integer base64EncodingOption)
Returns the public key retrieved from the keystore. final Boolean
exists(String keyName)
Query the keystore for a matching key name. final PrivateKey
getPrivateKey(String keyName)
Query the Keystore for the private key. final SecretKey
getSecretKey(String keyName)
final PublicKey
getPublicKey(String keyName)
final <T extends Any> T
signData(String keyName, String algorithm, T dataToSign, Integer base64EncodingOption)
final <T extends Any> T
signData(BiometricPrompt.CryptoObject cryptoObject, T dataToSign, Integer base64EncodingOption)
final String
getKeystoreType()
final Unit
setKeystoreType(String keystoreType)
final Integer
getKeySize()
final Unit
setKeySize(Integer keySize)
final ArrayList<String>
getSupportedAlgorithms()
-
-
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 pairalgorithm
- the standard string name of the algorithm to generate the key pairauthenticationRequired
- 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 pairbase64EncodingOption
- 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
-
getSecretKey
@Nullable() final SecretKey getSecretKey(String keyName)
-
getPublicKey
final PublicKey getPublicKey(String keyName)
-
signData
final <T extends Any> T signData(String keyName, String algorithm, T dataToSign, Integer base64EncodingOption)
-
signData
final <T extends Any> T signData(BiometricPrompt.CryptoObject cryptoObject, T dataToSign, Integer base64EncodingOption)
-
getKeystoreType
final String getKeystoreType()
-
setKeystoreType
final Unit setKeystoreType(String keystoreType)
-
getKeySize
final Integer getKeySize()
-
setKeySize
final Unit setKeySize(Integer keySize)
-
getSupportedAlgorithms
final ArrayList<String> getSupportedAlgorithms()
-
-
-
-