• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Encrypt file using public key?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This seems like it should be simple, but I'm getting confused. I have a binary file which I've discovered contains two keys: A Master and a Sub.

I've been able to read the file as a byte array from the file system, then add it to the keyStore using the method:


I've verified that the key exists using:



which returns true. I can also delete the key from the keyStore using:



Now, I'd like to use the public key to encrypt a file, but I'm unable to get a reference to the Key using:



Is there something I'm missing?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try the following:

KeystoreManager.setCacertsFile(cacertsFile);
PrivateKey privKey= KeystoreManager.getPrivKey();
X509Certificate[] certChain = KeystoreManager.getCertChain();

Set the keystore manager to point to the file that contains your keys, and then retrieve the corresponding public and private keys.

Originally posted by James Tikalsky:
This seems like it should be simple, but I'm getting confused. I have a binary file which I've discovered contains two keys: A Master and a Sub.

I've been able to read the file as a byte array from the file system, then add it to the keyStore using the method:


I've verified that the key exists using:



which returns true. I can also delete the key from the keyStore using:



Now, I'd like to use the public key to encrypt a file, but I'm unable to get a reference to the Key using:



Is there something I'm missing?

reply
    Bookmark Topic Watch Topic
  • New Topic