feat: add java keystore certificate option for pdf signing

This commit is contained in:
sbplat
2024-01-03 21:51:30 -05:00
parent d96a3db60a
commit 97f581ad6d
4 changed files with 121 additions and 133 deletions

View File

@@ -81,6 +81,7 @@ public class CertSignController {
MultipartFile privateKeyFile = request.getPrivateKeyFile();
MultipartFile certFile = request.getCertFile();
MultipartFile p12File = request.getP12File();
MultipartFile jksfile = request.getJksFile();
String password = request.getPassword();
Boolean showSignature = request.isShowSignature();
String reason = request.getReason();
@@ -95,10 +96,6 @@ public class CertSignController {
KeyStore ks = null;
switch (certType) {
case "PKCS12":
ks = KeyStore.getInstance("PKCS12");
ks.load(p12File.getInputStream(), password.toCharArray());
break;
case "PEM":
ks = KeyStore.getInstance("JKS");
ks.load(null);
@@ -107,6 +104,14 @@ public class CertSignController {
ks.setKeyEntry(
"alias", privateKey, password.toCharArray(), new Certificate[] {cert});
break;
case "PKCS12":
ks = KeyStore.getInstance("PKCS12");
ks.load(p12File.getInputStream(), password.toCharArray());
break;
case "JKS":
ks = KeyStore.getInstance("JKS");
ks.load(jksfile.getInputStream(), password.toCharArray());
break;
default:
throw new IllegalArgumentException("Invalid cert type: " + certType);
}

View File

@@ -14,7 +14,7 @@ public class SignPDFWithCertRequest extends PDFFile {
@Schema(
description = "The type of the digital certificate",
allowableValues = {"PKCS12", "PEM"})
allowableValues = {"PEM", "PKCS12", "JKS"})
private String certType;
@Schema(
@@ -28,6 +28,9 @@ public class SignPDFWithCertRequest extends PDFFile {
@Schema(description = "The PKCS12 keystore file (required for PKCS12 type certificates)")
private MultipartFile p12File;
@Schema(description = "The JKS keystore file (Java Key Store)")
private MultipartFile jksFile;
@Schema(description = "The password for the keystore or the private key")
private String password;