没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
public static void generateXMLDigitalSignature(String originalXmlFilePath, String destnSignedXmlFilePath)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyException, FileNotFoundException, SAXException, IOException, ParserConfigurationException, MarshalException, XMLSignatureException, TransformerException, KeyStoreException, CertificateException, UnrecoverableEntryException, InstantiationException, IllegalAccessException, ClassNotFoundException
{
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
Reference ref = fac.newReference
("#DataObjectId", fac.newDigestMethod(DigestMethod.SHA1, null),
Collections.singletonList
(fac.newTransform
(Transform.ENVELOPED, (TransformParameterSpec) null)),
null, null);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
org.w3c.dom.Document doc = dbf.newDocumentBuilder().parse(new FileInputStream(originalXmlFilePath));
org.w3c.dom.Element documentElement = doc.getDocumentElement();
DOMStructure domStructure = new DOMStructure(documentElement);
XMLObject newXMLObject = fac.newXMLObject(Collections.singletonList(domStructure), "DataObjectId", null, null);
SignedInfo si = fac.newSignedInfo
(fac.newCanonicalizationMethod(
CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec)null), fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null),
Collections.singletonList(ref));
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream(keyStoreSignFilePath), keyStoreSignFilePassword.toCharArray());
KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry)ks.getEntry(privateKey, new KeyStore.PasswordProtection(privateKeyPassword.toCharArray()));
X509Certificate cert = (X509Certificate)keyEntry.getCertificate();
/* //直接读取证书
CertificateFactory cf = CertificateFactory.getInstance("X.509");
FileInputStream fis = new FileInputStream(new File("e:/gdmlhenc.cer"));
X509Certificate cert = (X509Certificate) cf.generateCertificate(fis);
fis.close();
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyException, FileNotFoundException, SAXException, IOException, ParserConfigurationException, MarshalException, XMLSignatureException, TransformerException, KeyStoreException, CertificateException, UnrecoverableEntryException, InstantiationException, IllegalAccessException, ClassNotFoundException
{
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
Reference ref = fac.newReference
("#DataObjectId", fac.newDigestMethod(DigestMethod.SHA1, null),
Collections.singletonList
(fac.newTransform
(Transform.ENVELOPED, (TransformParameterSpec) null)),
null, null);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
org.w3c.dom.Document doc = dbf.newDocumentBuilder().parse(new FileInputStream(originalXmlFilePath));
org.w3c.dom.Element documentElement = doc.getDocumentElement();
DOMStructure domStructure = new DOMStructure(documentElement);
XMLObject newXMLObject = fac.newXMLObject(Collections.singletonList(domStructure), "DataObjectId", null, null);
SignedInfo si = fac.newSignedInfo
(fac.newCanonicalizationMethod(
CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec)null), fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null),
Collections.singletonList(ref));
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream(keyStoreSignFilePath), keyStoreSignFilePassword.toCharArray());
KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry)ks.getEntry(privateKey, new KeyStore.PasswordProtection(privateKeyPassword.toCharArray()));
X509Certificate cert = (X509Certificate)keyEntry.getCertificate();
/* //直接读取证书
CertificateFactory cf = CertificateFactory.getInstance("X.509");
FileInputStream fis = new FileInputStream(new File("e:/gdmlhenc.cer"));
X509Certificate cert = (X509Certificate) cf.generateCertificate(fis);
fis.close();
资源评论
- 文清---2019-01-10还不错,可以参考下
wenyilu
- 粉丝: 4
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- springboot-mavenBaseDemo 内容包含:springboot的maven基础状态,1.8JDK可以直接运行
- otis rsl远程串行接口协议标准.pdf
- buildx构建镜像时所需的镜像文件
- F103-霸道开发板2.8寸电阻触摸屏例程.rar
- Google(高德)地图瓦片python代码下载
- Python实现输出杨辉三角形
- polsarpro官方教程、操作说明 PolSARpro v5.0 Software Training Course
- STM32 TouchGFX的使用二图片显示
- buildx镜像文件,也可以通过网上其他方式获取
- 【中级软件设计师】上午题12-软件工程(2):单元测试、黑盒测试、白盒测试、软件运行与维护
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功