Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KeyStore get key without password

I need to know if its possible to retrieve a key from a KeyStore without providing the 'storepass'. The documentation here says that "When retrieving information from the keystore, the password is optional; if no password is given, the integrity of the retrieved information cannot be checked and a warning is displayed"

However when I try to get the Key without a password I get "java.lang.IllegalArgumentException: password can't be null" exception.

Following is how I created the KeyStore

keytool -genseckey -alias "myKey" -keystore KEYSTORE.jks -storepass "password" -storetype "JCEKS" -keyalg AES -keysize 128

And I tried to retrieve it as follows

final KeyStore keyStore = KeyStore.getInstance("JCEKS");
keyStore.load(new FileInputStream(new File("C:\\temp\\keytool\\KEYSTORE.jks")), 
  null);
final Key key = keyStore.getKey("myKey", null);

Which throws the following exception

java.lang.IllegalArgumentException: password can't be null
at com.sun.crypto.provider.SunJCE_z.<init>(DashoA13*..)
at com.sun.crypto.provider.JceKeyStore.engineGetKey(DashoA13*..)
at java.security.KeyStore.getKey(KeyStore.java:763)

Have I misunderstood the documentation completely? Is there any other way around this, as I don't see the point in storing the 'storepass' in clear in my code where everyone can see it, therefore making the password useless.

like image 346
Nishant Avatar asked Mar 18 '12 12:03

Nishant


People also ask

What do I do if I forgot my keystore password?

It's unfortunate, but when you lose your keystore, or the password to your keystore, your application is orphaned. The only thing you can do is resubmit your app to the market under a new key.

How do I find my keystore secret key?

To obtain the secret/symmetric or private key from the Android Keystore use KeyStore. getKey(String, null) or KeyStore. getEntry(String, null) . To obtain the public key from the Android Keystore use java.

Can keystore be hacked?

Since the keystore file is secured with a password, we have used the brute-force and the dictionary attack to crack the password of the keystore file in Ethereum wallets. Our results showed that the dictionary attack is more efficient to hack the keystore file than the brute-force attack.


1 Answers

If storepass (which is used to access the private key) is not provided then it will try to use the keypass i.e. the keystore password, which you also don't provide.
That is why you get the exception.
You can not have both the keypass and storepass null
From your link:

For a -keypass option, if you do not specify the option on the command line, keytool will first attempt to use the keystore password to recover the private/secret key, and if this fails, will then prompt you for the private/secret key password

like image 117
Cratylus Avatar answered Sep 28 '22 06:09

Cratylus