Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set key size for KeyPairGeneratorSpec on API 18?

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?

like image 714
Jonik Avatar asked Oct 12 '16 12:10

Jonik


1 Answers

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));
like image 143
Bryan Avatar answered Sep 25 '22 02:09

Bryan