码迷,mamicode.com
首页 > 编程语言 > 详细

Java操作证书

时间:2019-01-20 22:52:46      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:import   null   ati   nbsp   col   cer   har   tty   try   


import java.io.FileInputStream;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.util.Enumeration;


public
static void GetPrivateKey() { try{ KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(new FileInputStream("C:\\Program Files\\Java\\jre7\\bin\\xiaoyaodijun.keystore"), "7391428".toCharArray()); KeyPair keyPair = getPrivateKey2(keystore, "xiaoyaodijun.keystore", "7391428".toCharArray()); PrivateKey privateKey = keyPair.getPrivate(); System.out.println("private key = " + privateKey); }catch(Exception ex){} } public static KeyPair getPrivateKey2(KeyStore keystore, String alias, char[] password) { try { Key key=keystore.getKey(alias,password); if(key instanceof PrivateKey) { Certificate cert=keystore.getCertificate(alias); PublicKey publicKey=cert.getPublicKey(); return new KeyPair(publicKey,(PrivateKey)key); } }catch (Exception e) { } return null; }

 

Java操作证书

标签:import   null   ati   nbsp   col   cer   har   tty   try   

原文地址:https://www.cnblogs.com/taisuyuanqing/p/10296488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!