扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:朱先忠编译 来源:天极开发 2007年10月13日
关键字:
在本页阅读全文(共6页)
public class Validate { public static void main(String[] args) throws Exception { //第一步 String providerName = System.getProperty("jsr105Provider","org.jcp.XML.dsig.internal.dom.XMLDSigRI"); XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM",(Provider) Class.forName(providerName).newInstance()); //第二步 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().parse(new FileInputStream(args[0])); //第三步 NodeList nl = doc.getElementsByTagNameNS(XMLSignature.xmlNS,"Signature"); if (nl.getLength() == 0) { throw new Exception("Cannot find Signature element!"); } //第四步,分为情形4.0,4.1,4.2或4.3 //第4.0种情形 DOMValidateContext valContext = new DOMValidateContext(new KeyStoreKeySelector(), nl.item(0)); //第4.1种情形,需要Sign.java中的第6.1种情形 // DOMValidateContext valContext = new DOMValidateContext( // new KeyValueKeySelector(), nl.item(0)); //第4.2种情形,需要Sign.java中的第6.2种情形 // KeyStore ks = KeyStore.getInstance("JKS"); // FileInputStream fis = new FileInputStream("./etc/bizkeystore"); // ks.load(fis,"sp1234".toCharArray()); // fis.close(); // X509KeySelector x509ks = new X509KeySelector(ks); // DOMValidateContext valContext = new DOMValidateContext(x509ks, nl.item(0)); //第4.3中情形 // PublicKey pKey = KeyStoreInfo.getPublicKey("./etc/bizkeystore", // "sp1234", "biz"); //第五步 XMLSignature signature = fac.unmarshalXMLSignature(valContext); //XMLSignature signature = fac.unmarshalXMLSignature(new DOMStructure(nl.item(0))); //第六步 boolean coreValidity = signature.validate(valContext); //检查核心校验状态 if (coreValidity == false) { System.err.println("Signature failed core validation!"); boolean sv = signature.getSignatureValue().validate(valContext); System.out.println("Signature validation status: " + sv); //每一个Reference的检查校验状态 Iterator i = signature.getSignedInfo().getReferences().iterator(); for (int j = 0; i.hasNext(); j++) { boolean refValid = ((Reference) i.next()).validate(valContext); System.out.println("Reference (" + j + ") validation status: "+ refValid); } } else { System.out.println("Signature passed core validation!"); } } } |
public DOMValidateContext(Key validatingKey,Node node) |
public abstract KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException public static KeySelector singletonKeySelector(Key key) |
public abstract XMLSignature unmarshalXMLSignature(XMLValidateContext context) throws MarshalException |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者