I have used KeyPairGenerator
to generate a RSA key pair. If I'm not wrong, the KeyStore is only used to store certificates and not keys. How can I properly store the private key on the computer?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You can do something like this:
The save function:
And read the same way back:
Reading private key is similar.
http://snipplr.com/view/18368/
OR
http://docs.oracle.com/javase/1.5.0/docs/api/java/security/KeyStore.html
OR
http://java.sun.com/docs/books/tutorial/security/apisign/vstep2.html This is most Promising
OR
It's impossible to secure a key in an untrusted environment. You can obfuscate your code, you can create a key from arbitrary variables, whatever. Ultimately, assuming that you use the standard javax.crypto library, you have to call Mac.getInstance(), and sometime later you'll call init() on that instance. Someone who wants your key will get it.
However, I think the solution is that you tie the key to the environment, not the program. A signature is meant to say that the data originated from a known source, and has not been tampered with since that source provided it. Currently, you're trying to say "guarantee that my program produced the data." Instead, change your requirement to "guarantee that a particular user of my program produced the data." The onus is then shifted to that user to take care of his/her key.
This block of code will generate and store a KeyPair on the AndroidKeyStore. (NOTE: Exception catches omitted)
Depending on the format of your private key you might need to convert it to a format the java keytool can use.
But if it is in a keytool supported format you should be able yo just import it using keytool. more info at:
http://docs.oracle.com/javase/tutorial/security/toolfilex/rstep1.html
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/keytool.html