• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Private Key generated in Keytool  RSS feed

 
Jerry Girgich
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anyway to use the private key generated in keytool in a Java program without placing it into a file or certificate? Like is there a getPrivateKey method or something similar?
 
Henry Wong
author
Sheriff
Posts: 23028
120
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerry Girgich wrote:Is there anyway to use the private key generated in keytool in a Java program without placing it into a file or certificate? Like is there a getPrivateKey method or something similar?


First, the certificate does *not* contain the private key.... so, obviously, there is no way to get it from the certificate object. The reason is, of course, certificates are given out by certificate authority, for authentication purposes, and for encryption too.

If the certificate contains the private key, then authentication will break -- as everyone can prove itself as the owner, since he/she now has the private key. Additionally, anyone would be able to decrypt the payload too, defeating the purpose of encryption, as the private key is for decrypting (when the public key encrypted the payload).

As for the public/private key files, that are generated, it is just bits in a particular format. There are tools that will convert the format, even to bytes, so that you can embedded it in your program, or load it onto some secure location.

Henry
 
Jerry Girgich
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote: As for the public/private key files, that are generated, it is just bits in a particular format. There are tools that will convert the format, even to bytes, so that you can embedded it in your program, or load it onto some secure location.


Is there any way to load the keystore where the private key is located, in my program and then use the private key?


 
Jerry Girgich
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or how would I generate a file for the private key?
 
Henry Wong
author
Sheriff
Posts: 23028
120
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerry Girgich wrote:
Is there any way to load the keystore where the private key is located, in my program and then use the private key?


Based on your other topic, (https://coderanch.com/t/681062/Decryption-private-key-jks-file), it looks like you already found your answer to this topic.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!