本文整理汇总了Java中com.sun.org.apache.xml.internal.security.keys.KeyInfo.getX509Certificate方法的典型用法代码示例。如果您正苦于以下问题:Java KeyInfo.getX509Certificate方法的具体用法?Java KeyInfo.getX509Certificate怎么用?Java KeyInfo.getX509Certificate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.org.apache.xml.internal.security.keys.KeyInfo
的用法示例。
在下文中一共展示了KeyInfo.getX509Certificate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: engineLookupResolveX509Certificate
import com.sun.org.apache.xml.internal.security.keys.KeyInfo; //导入方法依赖的package包/类
/** {@inheritDoc}. */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
}
if (!engineCanResolve(element, baseURI, storage)) {
return null;
}
try {
KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
if (referent != null) {
return referent.getX509Certificate();
}
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
}
}
return null;
}
示例2: main
import com.sun.org.apache.xml.internal.security.keys.KeyInfo; //导入方法依赖的package包/类
/**
* Punto de inicio
*/
public static void main(String args[]) throws Exception {
com.sun.org.apache.xml.internal.security.Init.init();
String signatureFileName = "signature.xml";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
File f = new File(signatureFileName);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new java.io.FileInputStream(f));
Element sigElement = (Element) doc.getElementsByTagName("Signature").item(0);
XMLSignature signature = new XMLSignature(sigElement, f.toURL().toString());
// XMLSignature signature = new XMLSignature(sigElement, "http://pcancelacfd.sat.gob.mx");
KeyInfo keyInfo = signature.getKeyInfo();
if (keyInfo != null) {
X509Certificate cert = keyInfo.getX509Certificate();
if (cert != null) {
// Validamos la firma usando un certificado X509
if (signature.checkSignatureValue(cert)){
System.out.println("V�lido seg�n el certificado");
} else {
System.out.println("Inv�lido seg�n el certificado");
}
} else {
// No encontramos un Certificado intentamos validar por la cl�ve p�blica
PublicKey pk = keyInfo.getPublicKey();
if (pk != null) {
// Validamos usando la clave p�blica
if (signature.checkSignatureValue(pk)){
System.out.println("V�lido seg�n la clave p�blica");
} else {
System.out.println("Inv�lido seg�n la clave p�blica");
}
} else {
System.out.println("No podemos validar, tampoco hay clave p�blica");
}
}
} else {
System.out.println("No ha sido posible encontrar el KeyInfo");
}
}