|
@@ -55,10 +55,10 @@ public class ItextUtils {
|
|
* @param password 密码
|
|
* @param password 密码
|
|
* @param issuerStr 颁发机构信息
|
|
* @param issuerStr 颁发机构信息
|
|
* @param subjectStr 使用者信息
|
|
* @param subjectStr 使用者信息
|
|
- * @param certificateCRL 颁发地址
|
|
|
|
|
|
+ * @param certificateCrl 颁发地址
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static Map<String, byte[]> createCert(String password, String issuerStr, String subjectStr, String certificateCRL) {
|
|
|
|
|
|
+ public static Map<String, byte[]> createCert(String password, String issuerStr, String subjectStr, String certificateCrl) {
|
|
|
|
|
|
Map<String, byte[]> result = new HashMap<String, byte[]>();
|
|
Map<String, byte[]> result = new HashMap<String, byte[]>();
|
|
ByteArrayOutputStream out = null;
|
|
ByteArrayOutputStream out = null;
|
|
@@ -70,7 +70,7 @@ public class ItextUtils {
|
|
keyStore.load(null, null);
|
|
keyStore.load(null, null);
|
|
KeyPair keyPair = getKey();
|
|
KeyPair keyPair = getKey();
|
|
// issuer与 subject相同的证书就是CA证书
|
|
// issuer与 subject相同的证书就是CA证书
|
|
- Certificate cert = generateCertificateV3(issuerStr, subjectStr, keyPair, result, certificateCRL, null);
|
|
|
|
|
|
+ Certificate cert = generateCertificateV3(issuerStr, subjectStr, keyPair, result, certificateCrl, null);
|
|
// cretkey随便写,标识别名
|
|
// cretkey随便写,标识别名
|
|
keyStore.setKeyEntry("cretkey", keyPair.getPrivate(), password.toCharArray(), new Certificate[]{cert});
|
|
keyStore.setKeyEntry("cretkey", keyPair.getPrivate(), password.toCharArray(), new Certificate[]{cert});
|
|
out = new ByteArrayOutputStream();
|
|
out = new ByteArrayOutputStream();
|
|
@@ -97,12 +97,12 @@ public class ItextUtils {
|
|
* @param subjectStr
|
|
* @param subjectStr
|
|
* @param keyPair
|
|
* @param keyPair
|
|
* @param result
|
|
* @param result
|
|
- * @param certificateCRL
|
|
|
|
|
|
+ * @param certificateCrl
|
|
* @param extensions
|
|
* @param extensions
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static Certificate generateCertificateV3(String issuerStr, String subjectStr, KeyPair keyPair, Map<String, byte[]> result,
|
|
public static Certificate generateCertificateV3(String issuerStr, String subjectStr, KeyPair keyPair, Map<String, byte[]> result,
|
|
- String certificateCRL, List<Extension> extensions) {
|
|
|
|
|
|
+ String certificateCrl, List<Extension> extensions) {
|
|
|
|
|
|
ByteArrayInputStream bout = null;
|
|
ByteArrayInputStream bout = null;
|
|
X509Certificate cert = null;
|
|
X509Certificate cert = null;
|
|
@@ -124,14 +124,14 @@ public class ItextUtils {
|
|
jBuilder.setSecureRandom(secureRandom);
|
|
jBuilder.setSecureRandom(secureRandom);
|
|
ContentSigner singer = jBuilder.setProvider(new BouncyCastleProvider()).build(privateKey);
|
|
ContentSigner singer = jBuilder.setProvider(new BouncyCastleProvider()).build(privateKey);
|
|
// 分发点
|
|
// 分发点
|
|
- ASN1ObjectIdentifier cRLDistributionPoints = new ASN1ObjectIdentifier("2.5.29.31");
|
|
|
|
- GeneralName generalName = new GeneralName(GeneralName.uniformResourceIdentifier, certificateCRL);
|
|
|
|
|
|
+ ASN1ObjectIdentifier crlDistributionPoints = new ASN1ObjectIdentifier("2.5.29.31");
|
|
|
|
+ GeneralName generalName = new GeneralName(GeneralName.uniformResourceIdentifier, certificateCrl);
|
|
GeneralNames seneralNames = new GeneralNames(generalName);
|
|
GeneralNames seneralNames = new GeneralNames(generalName);
|
|
DistributionPointName distributionPoint = new DistributionPointName(seneralNames);
|
|
DistributionPointName distributionPoint = new DistributionPointName(seneralNames);
|
|
DistributionPoint[] points = new DistributionPoint[1];
|
|
DistributionPoint[] points = new DistributionPoint[1];
|
|
points[0] = new DistributionPoint(distributionPoint, null, null);
|
|
points[0] = new DistributionPoint(distributionPoint, null, null);
|
|
- CRLDistPoint cRLDistPoint = new CRLDistPoint(points);
|
|
|
|
- builder.addExtension(cRLDistributionPoints, true, cRLDistPoint);
|
|
|
|
|
|
+ CRLDistPoint crlDistPoint = new CRLDistPoint(points);
|
|
|
|
+ builder.addExtension(crlDistributionPoints, true, crlDistPoint);
|
|
// 用途
|
|
// 用途
|
|
ASN1ObjectIdentifier keyUsage = new ASN1ObjectIdentifier("2.5.29.15");
|
|
ASN1ObjectIdentifier keyUsage = new ASN1ObjectIdentifier("2.5.29.15");
|
|
// | KeyUsage.nonRepudiation | KeyUsage.keyCertSign
|
|
// | KeyUsage.nonRepudiation | KeyUsage.keyCertSign
|
|
@@ -183,8 +183,8 @@ public class ItextUtils {
|
|
// ST: 州或省份名称 C: 单位的两字母国家代码
|
|
// ST: 州或省份名称 C: 单位的两字母国家代码
|
|
String issuerStr = "CN=天天凭证,OU=研发部,O=gitbook有限公司,C=CN,E=gitbook@sina.com,L=北京,ST=北京";
|
|
String issuerStr = "CN=天天凭证,OU=研发部,O=gitbook有限公司,C=CN,E=gitbook@sina.com,L=北京,ST=北京";
|
|
String subjectStr = "CN=huangjinjin,OU=用户,O=借款人,C=CN,E=huangjinjin@sina.com,L=北京,ST=北京";
|
|
String subjectStr = "CN=huangjinjin,OU=用户,O=借款人,C=CN,E=huangjinjin@sina.com,L=北京,ST=北京";
|
|
- String certificateCRL = "https://gitbook.cn";
|
|
|
|
- Map<String, byte[]> result = createCert("123456", issuerStr, subjectStr, certificateCRL);
|
|
|
|
|
|
+ String certificateCrl = "https://gitbook.cn";
|
|
|
|
+ Map<String, byte[]> result = createCert("123456", issuerStr, subjectStr, certificateCrl);
|
|
|
|
|
|
// FileOutputStream outPutStream = new FileOutputStream("C:/pdf/keystore.p12"); // 生成.p12
|
|
// FileOutputStream outPutStream = new FileOutputStream("C:/pdf/keystore.p12"); // 生成.p12
|
|
// outPutStream.write(result.get("keyStoreData"));
|
|
// outPutStream.write(result.get("keyStoreData"));
|