How to store private key and public key in KeyStore

All.I am working on an Android project. I need to create an RSA key pair, then use them to communicate with others. I need to keep the private key and public key in a safe place, and I will find a KeyStore that can be used.

I see that KeyStore can store KeyStore.PrivateKeyEntry, but it needs a chain of Certificate []. I tried to create it, but could not ...

Is it possible to insert the example code used to store the private key and public key.

Many thanks!

+7
source share
1 answer

As you said, in order to save the private key in the keystore, you need a secret key (which you have) and a certificate chain for the corresponding public key. What you have is just a public key, you need to get a certificate from authority based on the public key. Yes, you can sign the certificate yourself. But I do not think that there is any built-in Java API for creating and self-signing a certificate programmatically.

There was a similar discussion in this thread. The decision made describes the storage of the private key and public key outside the keystore in a protected file .

Read more about Java cryptography architecture here http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html

Hope this helps.

+6
source

All Articles