This action will force synchronization from ofdrw/ofdrw, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
免责:电子文档的电子签章流程需要符合国家相关标准和规范。要产生具有效力的电子签名/签章,请使用符合国家密码局要求具有相关认证证书的密码设备进行。
ofdrw-sign
已经对OFD文档的电子签章过程完成比较高程度的封装,
开发者只需要关注如何实现签章即可。
引入依赖
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-sign</artifactId>
<version>1.19.1</version>
</dependency>
实现电子签章你需要下面步骤:
public static void main() throws Exception {
Path src = Paths.get("src/test/resources", "helloworld.ofd");
Path out = Paths.get("target/DigitalSign.ofd");
// 1. 构造签名引擎
try (OFDReader reader = new OFDReader(src);
OFDSigner signer = new OFDSigner(reader, out)) {
// 2. 实现电子签章容器
ExtendSignatureContainer signContainer = new YouImpContainer();
// 3. 设置签名模式
// signer.setSignMode(SignMode.WholeProtected);
signer.setSignMode(SignMode.ContinueSign);
// 4. 设置签名使用的扩展签名容器
signer.setSignContainer(signContainer);
// 5. 执行签名
signer.exeSign();
// 6. 关闭签名引擎,生成文档。
}
System.out.println(">> 生成文件位置: " + out.toAbsolutePath().toAbsolutePath());
}
为了便于测试的需要OFD R&W Sign模块中提供几个用于测试的签名扩展实现
请参考 扩展数字签名容器接口 实现电子签章功能。
假如你有一台符合国家标准规范具有型号证书的签章服务器,那么你可以这样实现:
public class MySESV4ontainer implements ExtendSignatureContainer {
@Override
public MessageDigest getDigestFnc() {
return new SM3.Digest();
}
@Override
public ASN1ObjectIdentifier getSignAlgOID() {
return GMObjectIdentifiers.sm2sign_with_sm3;
}
@Override
public byte[] sign(InputStream inData, String propertyInfo) throws IOException, GeneralSecurityException {
MessageDigest md = getDigestFnc();
// 签名原文杂凑值,也就是Signature.xml 文件的杂凑值
byte[] dataHash = md.digest(IOUtils.toByteArray(inData));
// TODO 调用电子签章服务器提供的电子签章接口完成电子签章。
}
@Override
public byte[] getSeal() throws IOException {
// TODO 从电子签章服务器上获取电子印章
}
@Override
public SigType getSignType() {
return SigType.Seal;
}
}
免责声明:为了合法验证OFD的电子签章有效性,请根据电子签章版本按照下面规范章节实现验证流程:
证书的验证也请由独立合法第三方机构进行验证!
OFD的签名签章验证过程有一下几步:
// 1. 构造一个验证引擎。
try (OFDReader reader = new OFDReader(src);
OFDValidator validator = new OFDValidator(reader)) {
// 2. 实现验证容器。
SignedDataValidateContainer dsc = new YouImpContainer(cert);
// 3. 实现验证容器。
validator.setValidator(dsc);
// 4. 执行验签验章。
validator.exeValidate();
// 5. 如果没有异常抛出说明验证成功。
}
如果想返还更多验证信息,请在
SignedDataValidateContainer
中对电子签章数据进行解析。
OFD R&W Sign模块中提供几个用于参考的验证容器实现,这些容器均只是验证签名值是否正确:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。