KeyGenParameterSpec.Builder
instead.@Deprecated public static final class KeyPairGeneratorSpec.Builder extends Object
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 = new Calendar(); Calendar end = new Calendar(); end.add(1, Calendar.YEAR); KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(mContext).setAlias("myKey") .setSubject(new X500Principal("CN=myKey")).setSerial(BigInteger.valueOf(1337)) .setStartDate(start.getTime()).setEndDate(end.getTime()).build();
Constructor and Description |
---|
Builder(Context context)
Deprecated.
Creates a new instance of the
Builder with the given
context . |
Modifier and Type | Method and Description |
---|---|
KeyPairGeneratorSpec |
build()
Deprecated.
Builds the instance of the
KeyPairGeneratorSpec . |
KeyPairGeneratorSpec.Builder |
setAlgorithmParameterSpec(AlgorithmParameterSpec spec)
Deprecated.
Sets the algorithm-specific key generation parameters.
|
KeyPairGeneratorSpec.Builder |
setAlias(String alias)
Deprecated.
Sets the alias to be used to retrieve the key later from a
KeyStore instance using the
AndroidKeyStore provider. |
KeyPairGeneratorSpec.Builder |
setEncryptionRequired()
Deprecated.
Indicates that this key pair must be encrypted at rest.
|
KeyPairGeneratorSpec.Builder |
setEndDate(Date endDate)
Deprecated.
Sets the end of the validity period for the self-signed certificate
of the generated key pair.
|
KeyPairGeneratorSpec.Builder |
setKeySize(int keySize)
Deprecated.
Sets the key size for the keypair to be created.
|
KeyPairGeneratorSpec.Builder |
setKeyType(String keyType)
Deprecated.
Sets the type of key pair (e.g.,
EC , RSA ) of the key pair to be
generated. |
KeyPairGeneratorSpec.Builder |
setSerialNumber(BigInteger serialNumber)
Deprecated.
Sets the serial number used for the self-signed certificate of the
generated key pair.
|
KeyPairGeneratorSpec.Builder |
setStartDate(Date startDate)
Deprecated.
Sets the start of the validity period for the self-signed certificate
of the generated key pair.
|
KeyPairGeneratorSpec.Builder |
setSubject(X500Principal subject)
Deprecated.
Sets the subject used for the self-signed certificate of the
generated key pair.
|
public Builder(Context context)
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.public KeyPairGeneratorSpec.Builder setAlias(String alias)
KeyStore
instance using the
AndroidKeyStore
provider.public KeyPairGeneratorSpec.Builder setKeyType(String keyType) throws NoSuchAlgorithmException
EC
, RSA
) of the key pair to be
generated. See KeyProperties
.KEY_ALGORITHM
constants.NoSuchAlgorithmException
public KeyPairGeneratorSpec.Builder setKeySize(int keySize)
public KeyPairGeneratorSpec.Builder setAlgorithmParameterSpec(AlgorithmParameterSpec spec)
RSAKeyGenParameterSpec
.public KeyPairGeneratorSpec.Builder setSubject(X500Principal subject)
public KeyPairGeneratorSpec.Builder setSerialNumber(BigInteger serialNumber)
public KeyPairGeneratorSpec.Builder setStartDate(Date startDate)
public KeyPairGeneratorSpec.Builder setEndDate(Date endDate)
public KeyPairGeneratorSpec.Builder setEncryptionRequired()
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.
KeyguardManager.isDeviceSecure()
public KeyPairGeneratorSpec build()
KeyPairGeneratorSpec
.KeyPairGeneratorSpec
IllegalArgumentException
- if a required field is missing