This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |