Skip to content

Instantly share code, notes, and snippets.

View jimmyMaci's full-sized avatar
:shipit:
Im on an IMF Mission

James Phelps jimmyMaci

:shipit:
Im on an IMF Mission
  • IMF
  • Langley, VA
View GitHub Profile
@jimmyMaci
jimmyMaci / to pkcs8 format
Last active July 24, 2018 16:32
Convert a PKCS#1 formatted java private key to PKCS#8
In BouncyCastle version 1.60 you can convert a PKCS#1 formatted private key to PKCS#8 with this method:
```
public static byte[] toPKCS8Format(final PrivateKey privateKey) throws IOException
{
String keyFormat = privateKey.getFormat();
if (keyFormat.equals("PKCS#1")) {
final byte[] encoded = privateKey.getEncoded();
final PrivateKeyInfo privateKeyInfo = PrivateKeyInfo.getInstance(encoded);
final ASN1Encodable asn1Encodable = privateKeyInfo.parsePrivateKey();