0

I have a encrypted private key string like this

-----BEGIN ENCRYPTED PRIVATE KEY-----
content
-----END ENCRYPTED PRIVATE KEY-----

I want to store the private key into my keystore file with certificate chain.

And I found that here is two functions in KeyStore.class.

  1. KeyStore.setKeyEntry(String alias, Key key, Char[] password, Certificate[] chain)
  2. KeyStore.setKeyEntry(String alias, byte[] key, Certificate[] chain)

What should I do in java code?

Or how to change the encrypted private key String to a java object?

Or how to change the encrypted private key String to a byte array which can be used for point 2 function?

Gentle Chen
  • 53
  • 1
  • 9
  • an encrypted private key String IS a java object. What you should do, is either read up a book about encryption, or ask a co-worker who is more experienced. This is way too broad for an SO question. – Stultuske Mar 25 '19 at 07:06
  • Yes, thanks for your advice. I just want to know how to convert the enrypted private key String to a java object, so that it can be used for point 1 function, or how to change it to a byte array which can be used fro point 2 function – Gentle Chen Mar 25 '19 at 07:14
  • so, you mean to say you don't know how to convert a String to a byte array? Stop thinking about encryption, and read up on the basics. Again: encryption is not something you want to dive into not knowing where you start from – Stultuske Mar 25 '19 at 07:21
  • yes, I have got you suggestion. In fact I know how to convert a String to a byte array. I just don't know how to convert to make the above functions work. Thanks for your advice, I'll read up on the basics. – Gentle Chen Mar 25 '19 at 07:27
  • @CarlosHeuberger yes, I need a Key instance, no matter it is Key object or byte array. I try so much solutions but it still can not work. – Gentle Chen Mar 25 '19 at 07:45
  • @CarlosHeuberger yes, I know that, but in fact I try use a lot of base64 dependencies to decode the content info, and the error is happen to the `PKCS8EncodedKeySpec ` generating, I searched in Google and found that my key is encrypted and it cannot be recognized, and then I used `EncryptedPrivateKeyInfo` to generate, but it throws `ObjectIdentifier() -- data isn't an object ID (tag = 48)`. This is the link for this error [link](https://stackoverflow.com/questions/55333924/decrypt-the-encrypted-private-key-data-isnt-an-object-id) – Gentle Chen Mar 26 '19 at 01:39

0 Answers0