I'm using this code to generate my RSA key pair under Api Level >= 23
KeyPairGenerator spec = KeyPairGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_RSA, Constants.KEYSTORE_NAME);
KeyGenParameterSpec keyGenParameterSpec = new KeyGenParameterSpec.Builder(
keyStoreAlias, KeyProperties.PURPOSE_DECRYPT | KeyProperties.PURPOSE_ENCRYPT)
.setKeySize(2048)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
.setKeyValidityStart(notBefore.getTime())
.setKeyValidityEnd(notAfter.getTime())
.setCertificateSubject(new X500Principal("CN=test"))
.setCertificateSerialNumber(BigInteger.ONE)
.build();
spec.initialize(keyGenParameterSpec);
KeyPair keyPair = spec.generateKeyPair();
If I try to build this code under api level < 23 compiler says "Call requires at least api level 23".
How can I convert this code to make it work with api level < 23?
setKeySize, setEncryptionPaddings .. these functions are not available api level < 23. How can I set encryption paddings for example in api level 14?