Builder
classBuilder
kotlin.Any | |
↳ | android.security.KeyPairGeneratorSpec.Builder |
Builder class for KeyPairGeneratorSpec
objects.
This will build a parameter spec for use with the Android KeyStore facility.
The required fields must be filled in with the builder.
Example:
Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); end.add(Calendar.YEAR, 1); KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(mContext).setAlias("myKey") .setSubject(new X500Principal("CN=myKey")).setSerialNumber(BigInteger.valueOf(1337)) .setStartDate(start.getTime()).setEndDate(end.getTime()).build();
Summary
Public constructors | |
---|---|
Creates a new instance of the |
Public methods | |
---|---|
KeyPairGeneratorSpec |
build() Builds the instance of the |
KeyPairGeneratorSpec.Builder! |
Sets the algorithm-specific key generation parameters. |
KeyPairGeneratorSpec.Builder |
Sets the alias to be used to retrieve the key later from a |
KeyPairGeneratorSpec.Builder |
Indicates that this key pair must be encrypted at rest. |
KeyPairGeneratorSpec.Builder |
setEndDate(endDate: Date) Sets the end of the validity period for the self-signed certificate of the generated key pair. |
KeyPairGeneratorSpec.Builder |
setKeySize(keySize: Int) Sets the key size for the keypair to be created. |
KeyPairGeneratorSpec.Builder |
setKeyType(keyType: String) Sets the type of key pair (e.g., |
KeyPairGeneratorSpec.Builder |
setSerialNumber(serialNumber: BigInteger) Sets the serial number used for the self-signed certificate of the generated key pair. |
KeyPairGeneratorSpec.Builder |
setStartDate(startDate: Date) Sets the start of the validity period for the self-signed certificate of the generated key pair. |
KeyPairGeneratorSpec.Builder |
setSubject(subject: X500Principal) Sets the subject used for the self-signed certificate of the generated key pair. |
Public constructors
Builder
Builder(context: Context)
Creates a new instance of the Builder
with the given context
. The context
passed in may be used to pop up some UI to ask the user to unlock or initialize the Android KeyStore facility.
Parameters | |
---|---|
context |
Context: This value cannot be null . |
Public methods
build
funbuild(): KeyPairGeneratorSpec
Deprecated: Deprecated in Java.
Builds the instance of the KeyPairGeneratorSpec
.
Return | |
---|---|
KeyPairGeneratorSpec |
built instance of KeyPairGeneratorSpec This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if a required field is missing |
setAlgorithmParameterSpec
funsetAlgorithmParameterSpec(spec: AlgorithmParameterSpec): KeyPairGeneratorSpec.Builder!
Deprecated: Deprecated in Java.
Sets the algorithm-specific key generation parameters. For example, for RSA keys this may be an instance of java.security.spec.RSAKeyGenParameterSpec
.
Parameters | |
---|---|
spec |
AlgorithmParameterSpec: This value cannot be null . |
setAlias
funsetAlias(alias: String): KeyPairGeneratorSpec.Builder
Deprecated: Deprecated in Java.
Sets the alias to be used to retrieve the key later from a java.security.KeyStore
instance using the AndroidKeyStore
provider.
Parameters | |
---|---|
alias |
String: This value cannot be null . |
Return | |
---|---|
KeyPairGeneratorSpec.Builder |
This value cannot be null . |
setEncryptionRequired
funsetEncryptionRequired(): KeyPairGeneratorSpec.Builder
Deprecated: Data at rest encryption is enabled by default. If extra binding to the lockscreen credential is desired, use KeyGenParameterSpec.Builder#setUserAuthenticationRequired(boolean)
. This flag will be ignored from Android S.
Indicates that this key pair must be encrypted at rest. This will protect the key pair with the secure lock screen credential (e.g., password, PIN, or pattern).
Note that this feature requires that the secure lock screen (e.g., password, PIN, pattern) is set up, otherwise key pair generation will fail. Moreover, this key pair will be deleted when the secure lock screen is disabled or reset (e.g., by the user or a Device Administrator). Finally, this key pair cannot be used until the user unlocks the secure lock screen after boot.
Return | |
---|---|
KeyPairGeneratorSpec.Builder |
This value cannot be null . |
setEndDate
funsetEndDate(endDate: Date): KeyPairGeneratorSpec.Builder
Deprecated: Deprecated in Java.
Sets the end of the validity period for the self-signed certificate of the generated key pair.
Parameters | |
---|---|
endDate |
Date: This value cannot be null . |
Return | |
---|---|
KeyPairGeneratorSpec.Builder |
This value cannot be null . |
setKeySize
funsetKeySize(keySize: Int): KeyPairGeneratorSpec.Builder
Deprecated: Deprecated in Java.
Sets the key size for the keypair to be created. For instance, for a key type of RSA this will set the modulus size and for a key type of EC it will select a curve with a matching field size.
Return | |
---|---|
KeyPairGeneratorSpec.Builder |
This value cannot be null . |
setKeyType
funsetKeyType(keyType: String): KeyPairGeneratorSpec.Builder
Deprecated: Deprecated in Java.
Sets the type of key pair (e.g., EC
, RSA
) of the key pair to be generated. See KeyProperties
.KEY_ALGORITHM
constants.
Parameters | |
---|---|
keyType |
String: This value cannot be null . Value is android.security.keystore.KeyProperties#KEY_ALGORITHM_RSA , android.security.keystore.KeyProperties#KEY_ALGORITHM_EC , android.security.keystore.KeyProperties.KEY_ALGORITHM_XDH, android.security.keystore.KeyProperties#KEY_ALGORITHM_AES , android.security.keystore.KeyProperties#KEY_ALGORITHM_HMAC_SHA1 , android.security.keystore.KeyProperties#KEY_ALGORITHM_HMAC_SHA224 , android.security.keystore.KeyProperties#KEY_ALGORITHM_HMAC_SHA256 , android.security.keystore.KeyProperties#KEY_ALGORITHM_HMAC_SHA384 , or android.security.keystore.KeyProperties#KEY_ALGORITHM_HMAC_SHA512 |
Return | |
---|---|
KeyPairGeneratorSpec.Builder |
This value cannot be null . |
setSerialNumber
funsetSerialNumber(serialNumber: BigInteger): KeyPairGeneratorSpec.Builder
Deprecated: Deprecated in Java.
Sets the serial number used for the self-signed certificate of the generated key pair.
Parameters | |
---|---|
serialNumber |
BigInteger: This value cannot be null . |
Return | |
---|---|
KeyPairGeneratorSpec.Builder |
This value cannot be null . |
setStartDate
funsetStartDate(startDate: Date): KeyPairGeneratorSpec.Builder
Deprecated: Deprecated in Java.
Sets the start of the validity period for the self-signed certificate of the generated key pair.
Parameters | |
---|---|
startDate |
Date: This value cannot be null . |
Return | |
---|---|
KeyPairGeneratorSpec.Builder |
This value cannot be null . |
setSubject
funsetSubject(subject: X500Principal): KeyPairGeneratorSpec.Builder
Deprecated: Deprecated in Java.
Sets the subject used for the self-signed certificate of the generated key pair.
Parameters | |
---|---|
subject |
X500Principal: This value cannot be null . |
Return | |
---|---|
KeyPairGeneratorSpec.Builder |
This value cannot be null . |