Skip to content

Instantly share code, notes, and snippets.

@babafeng
Created January 3, 2017 06:38
Show Gist options
  • Save babafeng/a294b286c16fa7354625fb3b605bf32f to your computer and use it in GitHub Desktop.
Save babafeng/a294b286c16fa7354625fb3b605bf32f to your computer and use it in GitHub Desktop.
// keystore pass
String store_password = "storepass";
// alias
String alias = "feng";
// key pass
String private_password = "keypass";
// 创建针对jks文件的输入流
InputStream inputStream = new FileInputStream("C:\Users\Vii26\Desktop\feng_pub.keystore");
// 创建KeyStore实例
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(inputStream, store_password.toCharArray());
// 获取私钥
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias,private_password.toCharArray());
// 获得公钥
PublicKey publicKey= keyStore.getCertificate(alias).getPublicKey();
System.out.println(privateKey);
System.out.println(publicKey);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment