Open klboke opened 6 years ago
输出标准格式pem文件项目:https://github.com/bcgit/bc-java
@Test
void generateRsaKey() throws Exception {
KeyPair keyPair = Keys.keyPairFor(SignatureAlgorithm.RS256); //or RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512
String publicKey = Encoders.BASE64.encode(keyPair.getPublic().getEncoded());
String privateKey = Encoders.BASE64.encode(keyPair.getPrivate().getEncoded());
System.err.println("queuing.app.publicKey=" + publicKey);
System.err.println("queuing.app.privateKey=" + privateKey);
String filename = "./rsa_public_key.pem";
PemWriter pemWriter = new PemWriter(new OutputStreamWriter(new FileOutputStream(filename)));
PemObject pemObject = new PemObject("RSA PUBLIC KEY", keyPair.getPublic().getEncoded());
pemWriter.writeObject(pemObject);
pemWriter.flush();
Assert.assertNotNull(pemObject);
}
http://www.kailing.pub/article/index/arcid/106.html
KL博客,kl博客,java,php学习心得技术分享,一个爱折腾的程序猿