有谁能告诉我如何从Java的RSAPrivateKey生成SSH兼容的私钥?我看了很多帖子但没有为我工作。
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
KeyPair kp = kpg.genKeyPair();
Writer out = new FileWriter(outfile);
String encodedPrivateKey = encoder.encodeToString(kp.getPrivate().getEncoded());
out.write(privKeyPrepend);
out.write(encodedPrivateKey);
out.write(privKeyAppend);
out.close();