SimpleASNWriter asn = new SimpleASNWriter();
RSAKeyInfo.writeRSAKeyInfo(asn, keyInfo);
payload = asn.toByteArray();
pem.setType(PEM.RSA_PRIVATE_KEY);
} else {
throw new InvalidSshKeyException(
"Unsupported J2SSH algorithm: " + algorithm);
}
pem.setPayload(payload);
pem.encryptPayload(payload, passphrase);
StringWriter w = new StringWriter();
pem.write(w);
return w.toString().getBytes("US-ASCII");
} catch (GeneralSecurityException e) {
//e.printStackTrace();
throw new InvalidSshKeyException(
"Can't read key due to cryptography problems: " + e);
} catch (IOException e) {
//e.printStackTrace();
throw new InvalidSshKeyException(
"Can't read key due to internal IO problems: " + e);
}
}