3

I am creating a RSA key pair in my Android KeyStore. I am using eclipse. I need to use KeyGenParameterSpec class to give my key an alias, so that I can delete it later, but I cant find this class. Can anyone let me know which jar would this be present in. The official page says that its present at android.security.keystore.KeyGenParameterSpec, but the problem is that I cant find this jar.

Thanks in advance!

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
Sid
  • 1,224
  • 3
  • 23
  • 48

1 Answers1

3

KeyGenParameterSpec is in the package android.security.keystore, but you can't see the constructor because it is annotate with @hide as you can see in the source code.

Quoting form the doclava documentation:

When applied to a package, class, method or field, @hide removes that node and all of its children from the documentation.

If you want to create a KeyGenParameterSpec you need to use the Builder:

new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
        .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
        .setUserAuthenticationRequired(true)
        .setUserAuthenticationValidityDurationSeconds(AUTHENTICATION_DURATION_SECONDS)
        .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
        .build()
Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
  • Thanks for the reply, the problem I am facing is that which jar will have this class? As in how do I use this in my eclipse project. Where can I find the jar which contains the android.security.keystore package – Sid Nov 23 '15 at 10:22
  • It is part of the Android framework. You don't need to add any particular jar. Please note that `KeyGenParameterSpec` is added in API level 23, so if you target a different version you can't see this class. – Mattia Maestrini Nov 23 '15 at 10:37
  • Got it, but I also tried using KeyPairGeneratorSpec, which is supported by the older libraries. In eclipse how do I access this framework then? How do I import this class? – Sid Nov 23 '15 at 10:51
  • It is also part of the Android framework. `KeyPairGeneratorSpec` is added is API level 18. Check that your target is at least 18. – Mattia Maestrini Nov 23 '15 at 10:55
  • I get that, the thing is I am not creating an android project in eclipse, so cant specify a target version. I am working on a normal java project where I need to use this class. therefore the question is how can I access this class – Sid Nov 23 '15 at 11:03
  • 1
    Download the `SDK Platform` from `Android SDK Manager`, then you can find the jar here `android-sdk-macosx/platforms/android-23/android.jar`. – Mattia Maestrini Nov 23 '15 at 11:07
  • So, is your issue solved? If the answer solved the problem, please mark it as 'accepted' by clicking the green check mark. – Mattia Maestrini Nov 24 '15 at 11:39
  • I ended up using android studio to get this done, but I am sure that with this jar it would have worked. So thanks for the help – Sid Nov 25 '15 at 06:13
  • @MattiaMaestrini this is my question https://stackoverflow.com/q/66760328/11630822 getting exception for my key alias in KeyGenParameterSpec.Builder.. if you have any idea about it, then please answer there. – Kousalya Mar 24 '21 at 07:44