CA加签测试方法

master
szy 1 week ago
parent 8757c54bae
commit e24ad0ae76
  1. 46
      micro-modules/micro-print/src/main/java/com/sinosoft/print/core/sign/strategy/SignByCA.java

@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Component @Component
@ -36,6 +39,49 @@ public class SignByCA implements SignInterface {
// return new byte[0]; // return new byte[0];
} }
public static void main(String[] args) throws Exception {
// ================== 1. 读取本地 PDF ==================
File inputPdf = new File("C:\\Users\\szy\\Desktop\\FZ接口\\a.pdf");
if (!inputPdf.exists()) {
throw new RuntimeException("PDF 文件不存在");
}
byte[] pdfBytes = Files.readAllBytes(inputPdf.toPath());
// ================== 2. 构造签章参数 ==================
String signNumber = "5CF6F98B6E5B2689";
String fileName = "input.pdf";
SignServiceConfigVo configVo = new SignServiceConfigVo();
configVo.setIp("10.0.2.71");
configVo.setPort(8888L);
configVo.setConnectTimeout(30000L);
configVo.setReadTimeout(30000L);
Map<String, Object> signParams = new HashMap<>();
// ================== 3. 调用签章方法 ==================
SignByCA signService = new SignByCA();
byte[] signedBytes = signService.sign(
pdfBytes,
signNumber,
configVo,
fileName,
signParams
);
// ================== 4. 保存签章后的 PDF ==================
File outputPdf = new File("C:\\Users\\szy\\Desktop\\FZ接口\\signed_output.pdf");
try (FileOutputStream fos = new FileOutputStream(outputPdf)) {
fos.write(signedBytes);
}
System.out.println("✅ 签章完成");
System.out.println("📄 签章后文件:" + outputPdf.getAbsolutePath());
}
@Override @Override
public byte[] sign(File signFile, String signNumber,SignServiceConfigVo configVo,String fileName, Map<String, Object> signParams) { public byte[] sign(File signFile, String signNumber,SignServiceConfigVo configVo,String fileName, Map<String, Object> signParams) {
//预留,暂不实现 //预留,暂不实现

Loading…
Cancel
Save