有没有更简单的方法来用Java签名XML文档? [英] Is there an easier way to sign an XML document in Java?

查看:55
本文介绍了有没有更简单的方法来用Java签名XML文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java 对XML文档进行数字签名.我有一个使用一些引用的实现,在

I'm trying to digitally sign an XML document using Java. I've got an implementation working with some references I've found that use various implementations in the javax.xml.crypto.dsig package.

但是,我当前的实现就像很多一样="http://www.java-tips.org/java-ee-tips/xml-digital-signature-api/using-the-java-xml-digital-signatur-2.html" rel ="noreferrer">我看过的示例-它很冗长,涉及使用来自 java.xml.crypto.dsig javax.xml.transform java.security 包等.好像我已经进入工厂工厂的工厂的土地一样,它花了我花了几个小时才弄清楚发生了什么.

However, my current implementation is like many of the examples I've looked at - it's rather verbose and involves using no less than 23 different API classes from the java.xml.crypto.dsig, javax.xml.transform, and java.security packages, among others. It feels like I've entered factory factory factory land, and it took me several hours just to figure out what was going on.

我的问题是,是否有更简单的方法来做到这一点?如果我有公共/私有密钥文件,并且想添加< Signature/> 到XML文档,那里有一个库,可以让我调用类似的东西:

My question is, is there an easier way to do this? If I've got public/private key files and I want to add a <Signature/> to an XML document, is there a library out there that just lets me call something like:

OutputStream signFile(InputStream xmlFile, File privateKey)

...没有所有的XMLSignatureFactory/CanonicalizationMethod/DOMSignContext疯狂吗?

...without all of the XMLSignatureFactory/CanonicalizationMethod/DOMSignContext craziness?

我对密码学不是很精通,对于像我这样的尝试熟悉数字签名的开发人员,Java提供的API似乎令人望而生畏.如果所有这些都是必要的,或者目前没有更友好的API,那很好,我愿意接受它作为答案.我只想知道我是否在这里不必要地走了艰难的路.

I'm not very well-versed in cryptography, and the Java-provided API seems rather daunting for developers like myself trying to become familiar with digital signing. If all of this is necessary or there's currently no friendlier API out there, that's fine and I'm willing to accept that as an answer. I'd just like to know if I'm unnecessarily taking the hard road here.

推荐答案

我查看了所有用于签名XML文件的选项,并决定采用非标准方法.这些标准太冗长了.另外,我不需要与标准兼容-我只需要在一块XML上签名即可.

I looked at all of the options for signing XML files and decided to go with a non-standard approach. The standards were all way too verbose. Also, I didn't need compatibility with the standards---I just needed signatures on a block of XML.

签名" XML块的最简单方法可能是使用带有分离签名的GPG.

Probably the easiest way to "sign" a block of XML is to use GPG with a detached signature.

这篇关于有没有更简单的方法来用Java签名XML文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆