当前位置: 首页>>代码示例>>Java>>正文


Java KeyInfo.getX509Certificate方法代码示例

本文整理汇总了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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:KeyInfoReferenceResolver.java

示例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");  
    }  
}
 
开发者ID:luislaredovelazquez,项目名称:ERP-en-Java,代码行数:49,代码来源:VerifySignature.java


注:本文中的com.sun.org.apache.xml.internal.security.keys.KeyInfo.getX509Certificate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。