javax.xml.crypto.dsig.Reference.getDigestInputStream()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中javax.xml.crypto.dsig.Reference.getDigestInputStream方法的一些代码示例,展示了Reference.getDigestInputStream的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference.getDigestInputStream方法的具体详情如下:
包路径:javax.xml.crypto.dsig.Reference
类名称:Reference
方法名:getDigestInputStream

Reference.getDigestInputStream介绍

[英]Returns the pre-digested input stream, if reference caching is enabled. This is the input to the digest operation during a validation or signing operation.
[中]如果启用了reference caching,则返回预摘要的输入流。这是验证或签名操作期间摘要操作的输入。

代码示例

代码示例来源:origin: net.shibboleth.metadata/aggregator-pipeline

/** {@inheritDoc} */
@Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
  Element element = item.unwrap();
  XMLSignature signature = xmlSigFactory.newXMLSignature(buildSignedInfo(element), buildKeyInfo());
  try {
    XMLSignContext context = new DOMSignContext(privKey, element, element.getFirstChild());
    
    // Enable caching reference values if required for debugging.
    if (isDebugPreDigest() && log.isDebugEnabled()) {
      context.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
    }
    
    // Perform the signature operation
    signature.sign(context);
    
    // Log the pre-digest data for debugging
    if (isDebugPreDigest() && log.isDebugEnabled()) {
      Reference ref = (Reference) signature.getSignedInfo().getReferences().get(0);
      String preDigest = CharStreams.toString(new InputStreamReader(ref.getDigestInputStream(), "UTF-8"));
      log.debug("pre digest: {}", preDigest);
    }
  } catch (Exception e) {
    log.error("Unable to create signature for element", e);
    throw new StageProcessingException("Unable to create signature for element", e);
  }
  return true;
}

代码示例来源:origin: org.apache.juddi/uddi-tck-base

System.out.println("    Calc Digest: " + calcDigValStr);
System.out.println("Expected Digest: " + expectedDigValStr);
InputStream is = ref.getDigestInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);

相关文章