• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Reading p12 file into keypair

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Can anyone share code on how to read a keypair from a PKCS12 file into a java KeyPair object?

Thanks,
KS
 
Kevin G Scott
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following seems to work.

KeyStore ks = KeyStore.getInstance("PKCS12");
FileInputStream fis = new FileInputStream("certFileName");
ks.load(fis, "password".toCharArray());

Enumeration aliasEnum = ks.aliases();

Key key = null;
Certificate cert = null;

while(aliasEnum.hasMoreElements()){
String keyName = (String)aliasEnum.nextElement();
key = ks.getKey(keyName,"password".toCharArray());
cert = ks.getCertificate(keyName);
}

KeyPair kp = new KeyPair(cert.getPublicKey(),(PrivateKey)key);
 
Look! I laid an egg! Why does it smell like that? Tiny ad, does this smell weird to you?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic