Package com.pd4ml.pdf.sign
Class CertificateUtils
- java.lang.Object
-
- com.pd4ml.pdf.sign.CertificateUtils
-
public final class CertificateUtils extends java.lang.ObjectLoads the signing identity (private key + certificate chain) used byPdfSigner.sign(java.io.File, java.io.File, com.pd4ml.pdf.sign.CertificateUtils.SigningIdentity, com.pd4ml.pdf.sign.SigningOptions), from any of three sources: a PKCS#12 (.p12/.pfx) keystore file (the private key lives in this process, in the clear, for the duration of the JVM), a PKCS#11 token/HSM (the private key never leaves the token -- every RSA/EC operation is delegated to it via the JDK'sSunPKCS11security provider), or a remote key held by a cloud KMS (AWS KMS, Azure Key Vault, GCP Cloud KMS, ...) reached through a user-suppliedRemoteSigner-- seeforRemoteKey(java.security.cert.Certificate[], com.pd4ml.pdf.sign.RemoteSigner).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCertificateUtils.SigningIdentityHolds the certificate chain to sign with, plus however this identity's private key operations actually get performed: an in-processPrivateKey(PKCS#12;CertificateUtils.SigningIdentity.getProvider()isnull, any JCA provider -- normally BouncyCastle -- may perform the RSA/EC operation), an opaquePrivateKeyhandle tied to one specificProvider(PKCS#11; that exact provider instance must perform the operation, since the key material never leaves the token), or no local key at all, only aRemoteSigner(cloud KMS).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CertificateUtils.SigningIdentityforRemoteKey(java.security.cert.Certificate[] certificateChain, RemoteSigner remoteSigner)Builds a signing identity for a key that lives entirely in a remote KMS (AWS KMS, Azure Key Vault, GCP Cloud KMS, or any signing service reachable over the network) -- there is no localPrivateKey; every signature is produced by callingremoteSigner.static CertificateUtils.SigningIdentityloadFromPkcs11(java.io.File pkcs11ConfigFile, char[] pin)Loads the first available private-key alias from a PKCS#11 token, configured by a standardSunPKCS11config file (the samename=.../library=.../slot=...format documented for-Djava.security.pkcs11.SunPKCS11.provider).static CertificateUtils.SigningIdentityloadFromPkcs11(java.io.File pkcs11ConfigFile, char[] pin, java.lang.String alias)LikeloadFromPkcs11(File, char[]), for a token holding more than one key.static CertificateUtils.SigningIdentityloadFromPkcs11(java.security.Provider pkcs11Provider, char[] pin, java.lang.String alias)LikeloadFromPkcs11(File, char[], String), for a caller that already has a configuredSunPKCS11Providerinstance (e.g.static CertificateUtils.SigningIdentityloadFromPkcs12(java.io.File keystoreFile, char[] password)Loads the first alias found in a PKCS#12 keystore (the common case for a keystore that holds exactly one signing identity).static CertificateUtils.SigningIdentityloadFromPkcs12(java.io.InputStream keystoreStream, char[] password, java.lang.String alias)Loads a specific alias from a PKCS#12 keystore.
-
-
-
Method Detail
-
loadFromPkcs12
public static CertificateUtils.SigningIdentity loadFromPkcs12(java.io.File keystoreFile, char[] password) throws PdfSigningException
Loads the first alias found in a PKCS#12 keystore (the common case for a keystore that holds exactly one signing identity).- Parameters:
keystoreFile- PKCS#12 file (.p12 / .pfx)password- keystore AND key password (PKCS#12 normally uses the same password for both)- Throws:
PdfSigningException
-
loadFromPkcs12
public static CertificateUtils.SigningIdentity loadFromPkcs12(java.io.InputStream keystoreStream, char[] password, java.lang.String alias) throws PdfSigningException
Loads a specific alias from a PKCS#12 keystore.- Parameters:
keystoreStream- PKCS#12 keystore contents; not closed by this methodpassword- keystore AND key passwordalias- alias to load, ornullto use the first alias holding a private key- Throws:
PdfSigningException
-
loadFromPkcs11
public static CertificateUtils.SigningIdentity loadFromPkcs11(java.io.File pkcs11ConfigFile, char[] pin) throws PdfSigningException
Loads the first available private-key alias from a PKCS#11 token, configured by a standardSunPKCS11config file (the samename=.../library=.../slot=...format documented for-Djava.security.pkcs11.SunPKCS11.provider). The private key is never copied into this process: every signature operation is performed on the token itself.- Parameters:
pkcs11ConfigFile- SunPKCS11 provider config file describing the token/HSM and its PKCS#11 librarypin- the token's PIN (used as theKeyStorepassword)- Throws:
PdfSigningException
-
loadFromPkcs11
public static CertificateUtils.SigningIdentity loadFromPkcs11(java.io.File pkcs11ConfigFile, char[] pin, java.lang.String alias) throws PdfSigningException
LikeloadFromPkcs11(File, char[]), for a token holding more than one key.- Throws:
PdfSigningException
-
loadFromPkcs11
public static CertificateUtils.SigningIdentity loadFromPkcs11(java.security.Provider pkcs11Provider, char[] pin, java.lang.String alias) throws PdfSigningException
LikeloadFromPkcs11(File, char[], String), for a caller that already has a configuredSunPKCS11Providerinstance (e.g. built with Java 9+'sProvider.configure(String), or shared across severalloadFromPkcs11calls against the same token so the token is only opened once).- Throws:
PdfSigningException
-
forRemoteKey
public static CertificateUtils.SigningIdentity forRemoteKey(java.security.cert.Certificate[] certificateChain, RemoteSigner remoteSigner) throws PdfSigningException
Builds a signing identity for a key that lives entirely in a remote KMS (AWS KMS, Azure Key Vault, GCP Cloud KMS, or any signing service reachable over the network) -- there is no localPrivateKey; every signature is produced by callingremoteSigner. Bring your own vendor SDK/HTTP client insideremoteSigner; this library has no vendor dependency of its own.- Parameters:
certificateChain- the signer's certificate (and any intermediates), matching the KMS keyremoteSigner- performs the actual sign operation against the KMS- Throws:
PdfSigningException
-
-