📄 testx509cert.java
字号:
String insuranceNumber = jitInsuranceNumber.getInsuranceNumber();
JITOrganizationCode jitOrganizationCode = extenParser.getJITOrganizationCode();
String organizationCode = jitOrganizationCode.getOrganizationCode();
JITICRegistrationNumber jitICRegistrationNumber = extenParser.getJITICRegistrationNumber();
String ICRegistrationNumber = jitICRegistrationNumber.getICRegistrationNumber();
JITTaxationNumeber jitTaxationNumeber = extenParser.getJITTaxationNumeber();
String taxationNumber = jitTaxationNumeber.getTaxationNumeber();
JITStationCode jitStationCode = extenParser.getJITStationCode();
String stationCode = jitStationCode.getStationCode();
JITCasteCode jitCasteCode = extenParser.getJITCasteCode();
String casteCode = jitCasteCode.getCasteCode();
byte byte0 = 9;
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e.toString());
}
}
public void generateTest()
{
try
{
cert.setSerialNumber(new DERInteger(0xa98ac7));
AlgorithmIdentifier alg = new AlgorithmIdentifier(PKCSObjectIdentifiers.sha1WithRSAEncryption);
cert.setSignatureAlg(alg);
X509Name issuer = new X509Name("CN=吉大,O=jit,ST=jilin,C=cn");
cert.setIssuer(issuer);
Time notBofore = new Time(new Date(System.currentTimeMillis()));
cert.setNotBefore(notBofore);
Time notAfter = new Time(new Date(System.currentTimeMillis() + 0x202fbf000L));
cert.setNotAfter(notAfter);
DERBitString subjectKeyUID = new DERBitString("12345".getBytes());
cert.setSubjectUniqueID(subjectKeyUID);
DERBitString issuerKeyUID = new DERBitString("12345".getBytes());
cert.setIssuerUniqueID(issuerKeyUID);
X509Name subject = new X509Name("c=cn,O=jit,CN=lijian");
cert.setSubject(subject);
SPKIParser spkiParser = new SPKIParser();
JKey jSPubKey = Parser.convert2JKey(1, spubKey);
SubjectPublicKeyInfo spki = spkiParser.generateSPKI(1, jSPubKey);
cert.setSubjectPubKeyInfo(spki);
Hashtable extensions = new Hashtable();
BasicConstraints bc = new BasicConstraints(true, 8);
DEROctetString octet = new DEROctetString(bc.getDERObject());
extensions.put(X509Extensions.BasicConstraints, new X509Extension(true, octet));
SPKIParser spkiParserex = new SPKIParser();
JKey jPubKey = Parser.convert2JKey(1, pubKey);
SubjectPublicKeyInfo spkiex = spkiParserex.generateSPKI(1, jPubKey);
BigInteger certIssuerSN = new BigInteger("667788");
X509Name certIssuer = new X509Name("CN=无线安全,C=cn");
GeneralName genName = new GeneralName(certIssuer);
GeneralNames genNames = new GeneralNames(new DERSequence(genName));
AuthorityKeyIdentifier authorityKeyID = new AuthorityKeyIdentifier(spkiex, genNames, certIssuerSN);
octet = new DEROctetString(authorityKeyID.getDERObject());
extensions.put(X509Extensions.AuthorityKeyIdentifier, new X509Extension(false, octet));
spkiex = spkiParserex.generateSPKI(1, jSPubKey);
SubjectKeyIdentifier subjectKeyID = new SubjectKeyIdentifier(spkiex);
octet = new DEROctetString(subjectKeyID.getDERObject());
extensions.put(X509Extensions.SubjectKeyIdentifier, new X509Extension(false, octet));
KeyUsage keyUsage = new KeyUsage(240);
octet = new DEROctetString(keyUsage.getDERObject());
extensions.put(X509Extensions.KeyUsage, new X509Extension(false, octet));
byte crlUrl[] = "http://172.16.1.50/crl".getBytes();
DEROctetString octetCRLUrl = new DEROctetString(crlUrl);
GeneralName generalName = new GeneralName(octetCRLUrl, 6);
X509Name x509Name = new X509Name("CN=crl,O=Jit,C=cn");
GeneralName genName2 = new GeneralName(x509Name);
ReasonFlags rs = new ReasonFlags(98);
DistributionPoint p1 = DistributionPoint.generatDistributionPoint(generalName, rs, genName2);
DistributionPoint p2 = DistributionPoint.generatDistributionPoint(genName2, null, null);
DistributionPoint ps[] = new DistributionPoint[2];
ps[0] = p1;
ps[1] = p2;
CRLDistPoint CRLPoint = new CRLDistPoint(ps);
DEROctetString octStr = new DEROctetString(Parser.writeDERObj2Bytes(CRLPoint.getDERObject()));
extensions.put(X509Extensions.CRLDistributionPoints, new X509Extension(false, octStr));
PolicyQualifierInfo policyQualifierInfo1 = new PolicyQualifierInfo("http://www.jit.com.cn/cps");
Vector vNumbers = new Vector();
vNumbers.add(new Integer(1));
PolicyQualifierInfo policyQualifierInfo2 = new PolicyQualifierInfo("JIT", vNumbers, "JIT WPKI");
PolicyQualifierInfo policyQualifierInfos[] = new PolicyQualifierInfo[2];
policyQualifierInfos[0] = policyQualifierInfo1;
policyQualifierInfos[1] = policyQualifierInfo2;
PolicyInformation policyInfomation = new PolicyInformation(policyQualifierInfos);
CertificatePolicies certificatePolicies = new CertificatePolicies(policyInfomation);
octet = new DEROctetString(certificatePolicies.getDERObject());
extensions.put(X509Extensions.CertificatePolicies, new X509Extension(false, octet));
DERGeneralizedTime priKeyNotBofore = new DERGeneralizedTime(new Date(System.currentTimeMillis()));
DERGeneralizedTime priKeyNotAfter = new DERGeneralizedTime(new Date(System.currentTimeMillis() + 0x202fbf000L));
PrivateKeyUsagePeriod priKeyUsagePeriod = new PrivateKeyUsagePeriod(priKeyNotBofore, priKeyNotAfter);
octet = new DEROctetString(priKeyUsagePeriod.getDERObject());
extensions.put(X509Extensions.PrivateKeyUsagePeriod, new X509Extension(false, octet));
Vector keyPurposeID = new Vector();
keyPurposeID.add(KeyPurposeId.id_kp_clientAuth);
keyPurposeID.add(KeyPurposeId.id_kp_codeSigning);
keyPurposeID.add(KeyPurposeId.id_kp_serverAuth);
ExtendedKeyUsage extendedKeyUsage = new ExtendedKeyUsage(keyPurposeID);
octet = new DEROctetString(extendedKeyUsage.getDERObject());
extensions.put(X509Extensions.ExtendedKeyUsage, new X509Extension(false, octet));
X509Name x509Location = new X509Name("CN=CA,O=Jit,C=cn");
GeneralName location = new GeneralName(x509Name);
AuthorityInformationAccess aia = new AuthorityInformationAccess(AuthorityInformationAccess.ID_CA_ISSUERS, location);
octet = new DEROctetString(aia.getDERObject());
extensions.put(X509Extensions.AuthorityInformationAccess, new X509Extension(false, octet));
X509Name xissuerAltName = new X509Name("CN=JIT,ST=JILIN,C=cn");
GeneralName gissuerAltName = new GeneralName(xissuerAltName);
GeneralNames issuerAltName = new GeneralNames(new DERSequence(gissuerAltName));
octet = new DEROctetString(issuerAltName.getDERObject());
extensions.put(X509Extensions.IssuerAlternativeName, new X509Extension(false, octet));
X509Name xsubjecAltName = new X509Name("CN=lj6684,C=cn");
GeneralName gsubjecAltName = new GeneralName(xsubjecAltName);
GeneralNames subjectAltName = new GeneralNames(new DERSequence(gsubjecAltName));
octet = new DEROctetString(subjectAltName.getDERObject());
extensions.put(X509Extensions.SubjectAlternativeName, new X509Extension(false, octet));
String policyID = "2.16.840.1.113733.1.7.1.1";
Hashtable table = new Hashtable();
table.put(policyID, policyID);
PolicyMappings policyMappings = new PolicyMappings(table);
octet = new DEROctetString(policyMappings.getDERObject());
extensions.put(X509Extensions.PolicyMappings, new X509Extension(false, octet));
X509Name x509NameConstraints = new X509Name("CN=NameContstraints,O=Jit,C=cn");
GeneralName genNameConstraints = new GeneralName(x509NameConstraints);
BigInteger maximum = new BigInteger("3");
GeneralSubtree permittedSubtree = new GeneralSubtree(genNameConstraints, null, maximum);
x509NameConstraints = new X509Name("O=Entrust,C=cn");
genNameConstraints = new GeneralName(x509NameConstraints);
GeneralSubtree excludedSubtree = new GeneralSubtree(genNameConstraints, null, maximum);
NameConstraints nameConstraints = new NameConstraints(permittedSubtree, excludedSubtree);
octet = new DEROctetString(nameConstraints.getDERObject());
extensions.put(X509Extensions.NameConstraints, new X509Extension(false, octet));
DERInteger requireEP = new DERInteger(new BigInteger("1"));
DERInteger inhibitPM = new DERInteger(new BigInteger("3"));
PolicyConstraints policyConstraints = new PolicyConstraints(requireEP, inhibitPM);
octet = new DEROctetString(policyConstraints.getDERObject());
extensions.put(X509Extensions.PolicyConstraints, new X509Extension(false, octet));
DERPrintableString printableString1 = new DERPrintableString("test1 for Subject Directory Atrributes");
DERPrintableString printableString2 = new DERPrintableString("test2 for Subject Directory Atrributes");
DEREncodableVector v = new DEREncodableVector();
v.add(printableString1);
v.add(printableString2);
DERObjectIdentifier derSDAID1 = new DERObjectIdentifier("1.2.840.2.1");
DERObjectIdentifier derSDAID2 = new DERObjectIdentifier("1.2.840.2.2");
Attribute attributes[] = new Attribute[2];
attributes[0] = new Attribute(derSDAID1, new DERSet(v));
attributes[1] = new Attribute(derSDAID2, new DERSet(v));
SubjectDirectoryAttributes sda = new SubjectDirectoryAttributes(attributes);
octet = new DEROctetString(sda.getDERObject());
extensions.put(X509Extensions.SubjectDirectoryAttributes, new X509Extension(false, octet));
DERPrintableString rCardNumber = new DERPrintableString("22240519800104");
DERUTF8String mCardNumber = new DERUTF8String("jfj194981");
DERPrintableString passportNumber = new DERPrintableString("CN454861278233");
JITIdentifyCode jitIdentifyCode = new JITIdentifyCode(rCardNumber, mCardNumber, passportNumber);
octet = new DEROctetString(jitIdentifyCode.getDERObject());
extensions.put(X509Extensions.JIT_IdentifyCode, new X509Extension(false, octet));
JITInsuranceNumber jitInsuranceNumber = new JITInsuranceNumber("BX55667788");
octet = new DEROctetString(jitInsuranceNumber.getDERObject());
extensions.put(X509Extensions.JIT_InsuranceNumber, new X509Extension(false, octet));
JITOrganizationCode jitOrganizationCode = new JITOrganizationCode("OC00512");
octet = new DEROctetString(jitOrganizationCode.getDERObject());
extensions.put(X509Extensions.JIT_OrganizationCode, new X509Extension(false, octet));
JITICRegistrationNumber jitICRegistrationNumber = new JITICRegistrationNumber("ICRN658658");
octet = new DEROctetString(jitICRegistrationNumber.getDERObject());
extensions.put(X509Extensions.JIT_ICRegistrationNumber, new X509Extension(false, octet));
JITTaxationNumeber jitTaxationNumeber = new JITTaxationNumeber("TN758758");
octet = new DEROctetString(jitTaxationNumeber.getDERObject());
extensions.put(X509Extensions.JIT_TaxationNumber, new X509Extension(false, octet));
JITStationCode jitStationCode = new JITStationCode("GA1233455");
octet = new DEROctetString(jitStationCode.getDERObject());
extensions.put(X509Extensions.JIT_StationCode, new X509Extension(false, octet));
JITCasteCode jitCasteCode = new JITCasteCode("GA458699439");
octet = new DEROctetString(jitCasteCode.getDERObject());
extensions.put(X509Extensions.JIT_CasteCode, new X509Extension(false, octet));
X509Extensions x509Extensions = new X509Extensions(extensions);
cert.setExtensions(x509Extensions);
JKey jPriKey = Parser.convert2JKey(2, priKey);
JCrypto jCrypto = new JCrypto();
jCrypto.initialize(0, null);
Session session = jCrypto.openSession(0);
cert.generateX509Cert(session, jPriKey, "D:/CFCATest.cer");
byte byte0 = 9;
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
public static void main(String args[])
{
TestX509Cert testX509Cert1 = new TestX509Cert();
testX509Cert1.generateTest();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -