Create Digital Certificates
PKCS12 (Public Key Cryptography Standard #12) format digital certificates usually contain a public key, a private key, and other information related to the certificate. PKCS12 is a standard format used to store security certificates, private keys, and other related information. This format is commonly used to export, backup, and share digital certificates and private keys which are used in secure communications and identity verification.
When creating a PKCS12 standard certificate, in addition to the data confirming your identity, a password is typically required to protect your certificate. Only those who possess the password can access the private key contained within and perform actions such as signing documents through the certificate.
This example shows how to create digital certificates:
// Generate certificate.
//
// Password: ComPDFKit
//
// info: /C=SG/O=ComPDFKit/D=R&D Department/CN=Alan/[email protected]
//
// C=SG: This represents the country code "SG," which typically stands for Singapore.
// O=ComPDFKit: This is the Organization (O) field, indicating the name of the organization or entity, in this case, "ComPDFKit."
// D=R&D Department: This is the Department (D) field, indicating the specific department within the organization, in this case, "R&D Department."
// CN=Alan: This is the Common Name (CN) field, which usually represents the name of the individual or entity. In this case, it is "Alan."
// [email protected]: Email is [email protected]
//
// CPDFCertUsage.CPDFCertUsageAll: Used for both digital signing and data validation simultaneously
//
// is_2048 = true: Enhanced security encryption
//
String password = "ComPDFKit";
CPDFOwnerInfo ownerInfo = new CPDFOwnerInfo();
ownerInfo.setCommonName("Alan");
ownerInfo.setOrgnize("ComPDFKit");
ownerInfo.setEmail("[email protected]");
ownerInfo.setCountry("SG");
ownerInfo.setOrgnizeUnit("R&D Department");
CPDFSignature.CertUsage flag = CPDFSignature.CertUsage.PDFDigSig;
File certFile = new File(rootDir + "/certificate/Certificate.pfx");
certFile.getParentFile().mkdirs();
boolean result = CPDFSignature.generatePKCS12Cert(ownerInfo, password, certFile.getAbsolutePath(), flag,true);
System.out.println("generatePKCS12Cert result: " + result);