java - Why keyStore.aliases() is empty for pkcs12 -


i'm trying load privatekey .p12 file using code:

    security.addprovider(new org.bouncycastle.jce.provider.bouncycastleprovider());     java.security.keystore keystore = keystore.getinstance("pkcs12", "bc");     keystore.load(new fileinputstream(new file("my_domain_com.p12")), password);     keystore.aliases().hasmoreelements(); //this false     java.security.privatekey privatekey = (privatekey) keystore.getkey("somealias", password);   

i'm trying find reason why there no aliases. i'm not able find. can reason empty alias? want private key , ecrypt text using key. there other apporach?

i have .cer file i'm not sure should use together.

is possible keystore has nothing in @ all? use java keytool command verify.

>keytool -list -v -keystore test.p12 -storetype pkcs12 enter keystore password:  keystore type: pkcs12 keystore provider: sunjsse  keystore contains 1 entry  alias name: test_alias creation date: sep 3, 2013 entry type: privatekeyentry certificate chain length: 1 certificate[1]: ... ... 

if there entries in keystore, should see "alias name" each one. if there no entries in keystore, see "your keystore contains 0 entries", , need import them keystore.

also, when encrypting, should encrypt else's public key, , decrypt private key. , encrypt public key, decrypt private key.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -