java https请求p12文件

桾楉叁杄 2015-03-27 06:33:05
如何利用java做https请求,关键证书是p12的,不是cert的,哪位大哥大姐帮解决一下啊。
...全文
304 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wingcain 2015-12-18
  • 打赏
  • 举报
回复
http://blog.csdn.net/cuiran/article/details/7816696 这个是原文程序地址,你看看能不能满足你要求
wingcain 2015-12-18
  • 打赏
  • 举报
回复
public class ReadP12Cert { /** * TODO * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub final String KEYSTORE_FILE = "证书路径"; final String KEYSTORE_PASSWORD = "证书密码"; final String KEYSTORE_ALIAS = "alias"; try { KeyStore ks = KeyStore.getInstance("PKCS12"); FileInputStream fis = new FileInputStream(KEYSTORE_FILE); // If the keystore password is empty(""), then we have to set // to null, otherwise it won't work!!! char[] nPassword = null; if ((KEYSTORE_PASSWORD == null) || KEYSTORE_PASSWORD.trim().equals("")) { nPassword = null; } else { nPassword = KEYSTORE_PASSWORD.toCharArray(); } ks.load(fis, nPassword); fis.close(); System.out.println("keystore type=" + ks.getType()); // Now we loop all the aliases, we need the alias to get keys. // It seems that this value is the "Friendly name" field in the // detals tab <-- Certificate window <-- view <-- Certificate // Button <-- Content tab <-- Internet Options <-- Tools menu // In MS IE 6. Enumeration enum1 = ks.aliases(); String keyAlias = null; if (enum1.hasMoreElements()) // we are readin just one certificate. { keyAlias = (String)enum1.nextElement(); System.out.println("alias=[" + keyAlias + "]"); } // Now once we know the alias, we could get the keys. System.out.println("is key entry=" + ks.isKeyEntry(keyAlias)); PrivateKey prikey = (PrivateKey) ks.getKey(keyAlias, nPassword); Certificate cert = ks.getCertificate(keyAlias); PublicKey pubkey = cert.getPublicKey(); System.out.println("cert class = " + cert.getClass().getName()); System.out.println("cert = " + cert); System.out.println("public key = " + pubkey); System.out.println("private key = " + prikey); } catch (Exception e) { e.printStackTrace(); } } }
桾楉叁杄 2015-03-30
  • 打赏
  • 举报
回复
自己顶一下,没人知道吗。。。。

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧