Android Keystore (with KeyPairGeneratorSpec
etc) was introduced in API level 18. However, the method KeyPairGeneratorSpec.Builder.setKeySize()
was only introduced in API level 19.
While supporting API level 18 (Android 4.3), is it possible to set the key size?
According to the documentation, it would seem as though API level 18 does support different RSA Key
sizes. But according to another source (referencing API level 18):
There is currently no way to specify key size or type and generated keys default to 2048 bit RSA.
Though, I suppose you should be able to use a different AlgorithmParameterSpec
, such as the old RSAKeyGenParameterSpec
available since API level 1; which takes a key size as a constructor argument:
keyPairGenerator.initialize(new RSAKeyGenParameterSpec(keySize, publicExponent));