Examples of DigestOutputStream


Examples of java.security.DigestOutputStream

      try {
    Field[] fields = getFields(clazz);
    MessageDigest md = MessageDigest.getInstance("SHA");
    DataOutputStream out =
        new DataOutputStream(
      new DigestOutputStream(new ByteArrayOutputStream(127),
                 md));
    Class c = clazz.getSuperclass();
    if (c != Object.class)
        // recursive call
        out.writeLong(findHash(c, marshaling).longValue());
View Full Code Here

Examples of java.security.DigestOutputStream

    private void computeHash() throws IOException, NoSuchAlgorithmException
    {
  hash = 0;
  MessageDigest md = MessageDigest.getInstance("SHA");
  DataOutputStream out = new DataOutputStream(
      new DigestOutputStream(new ByteArrayOutputStream(127),md));     
  out.writeUTF(name);    
  out.flush();
  byte[] digest = md.digest();
  for (int i = Math.min(8, digest.length); --i >= 0; ) {
      hash += ((long) (digest[i] & 0xFF)) << (i * 8);
 
View Full Code Here

Examples of java.security.DigestOutputStream

        } else
            try {
                ByteArrayOutputStream barr = new ByteArrayOutputStream(512);
                MessageDigest md = MessageDigest.getInstance("SHA");
                DigestOutputStream digestout = new DigestOutputStream(barr, md);
                DataOutputStream out = new DataOutputStream(digestout);

                Class superType = type.getSuperclass();
                if (superType != null) {
                    TypeDescriptor desc = getTypeRepository().getDescriptor(
View Full Code Here

Examples of java.security.DigestOutputStream

        byte[] block = new byte[blockSize];
        int count = 0;
        while (true) {
            MessageDigest messageDigest = MessageDigest.getInstance(HASH_ALGORITHM);
            ByteArrayOutputStream buff = new ByteArrayOutputStream();
            DigestOutputStream dout = new DigestOutputStream(buff, messageDigest);
            int blockLen = IOUtils.readFully(in, block, 0, block.length);
            count++;
            if (blockLen == 0) {
                break;
            } else if (blockLen < blockSizeMin) {
                idStream.write(TYPE_DATA);
                IOUtils.writeVarInt(idStream, blockLen);
                idStream.write(block, 0, blockLen);
                totalLength += blockLen;
            } else {
                dout.write(block, 0, blockLen);
                byte[] digest = messageDigest.digest();
                idStream.write(TYPE_HASH);
                IOUtils.writeVarInt(idStream, level);
                if (level > 0) {
                    IOUtils.writeVarLong(idStream, totalLength);
View Full Code Here

Examples of java.security.DigestOutputStream

    public byte[] getHash() {
        if (hash == null) {
            try {
                MessageDigest d = MessageDigest.getInstance("SHA-1");
                DigestOutputStream out = new DigestOutputStream(new OutputStream() {
                    @Override
                    public void write(byte[] buff, int off, int length) {
                        // ignore
                    }
                    @Override
View Full Code Here

Examples of java.security.DigestOutputStream

     * the digest value.
     */
    @Override
    public void write(OutputStream outputStream) throws IOException {
        getWrappedRepresentation().write(
                new DigestOutputStream(outputStream, this.computedDigest));
    }
View Full Code Here

Examples of org.apache.james.jdkim.canon.DigestOutputStream

            throw new PermFailException(
                    "Unsupported body canonicalization method: "
                            + sign.getBodyCanonicalisationMethod());
        }

        DigestOutputStream dout = new DigestOutputStream(md);

        OutputStream out = dout;
        if (DEEP_DEBUG)
            out = new DebugOutputStream(out);
        out = prepareCanonicalizerOutputStream(limit, relaxedBody, out);
View Full Code Here

Examples of org.apache.xml.security.stax.impl.util.DigestOutputStream

        String digestAlgo = securePart.getDigestMethod();
        if (digestAlgo == null) {
            digestAlgo = getSecurityProperties().getSignatureDigestAlgorithm();
        }

        DigestOutputStream digestOutputStream = createMessageDigestOutputStream(digestAlgo);
        InputStream inputStream = resourceResolver.getInputStreamFromExternalReference();

        SignaturePartDef signaturePartDef = new SignaturePartDef();
        signaturePartDef.setSecurePart(securePart);
        signaturePartDef.setSigRefId(externalReference);
        signaturePartDef.setExternalResource(true);
        signaturePartDef.setTransforms(securePart.getTransforms());
        signaturePartDef.setDigestAlgo(digestAlgo);

        try {
            if (securePart.getTransforms() != null) {
                signaturePartDef.setExcludeVisibleC14Nprefixes(true);
                Transformer transformer = buildTransformerChain(digestOutputStream, signaturePartDef, null);
                transformer.transform(inputStream);
                transformer.doFinal();
            } else {
                XMLSecurityUtils.copy(inputStream, digestOutputStream);
            }
            digestOutputStream.close();
        } catch (IOException e) {
            throw new XMLSecurityException(e);
        }

        String calculatedDigest = new String(Base64.encodeBase64(digestOutputStream.getDigestValue()));
        if (logger.isDebugEnabled()) {
            logger.debug("Calculated Digest: " + calculatedDigest);
        }

        signaturePartDef.setDigestValue(calculatedDigest);
View Full Code Here

Examples of org.apache.xml.security.stax.impl.util.DigestOutputStream

        } catch (NoSuchAlgorithmException e) {
            throw new XMLSecurityException(e);
        } catch (NoSuchProviderException e) {
            throw new XMLSecurityException(e);
        }
        return new DigestOutputStream(messageDigest);
    }
View Full Code Here

Examples of org.apache.xml.security.stax.impl.util.DigestOutputStream

                signaturePartDef.setDigestAlgo(securePart.getDigestMethod());
                if (signaturePartDef.getDigestAlgo() == null) {
                    signaturePartDef.setDigestAlgo(getSecurityProperties().getSignatureDigestAlgorithm());
                }

                DigestOutputStream digestOutputStream = createMessageDigestOutputStream(signaturePartDef.getDigestAlgo());
                InputStream inputStream = attachment.getSourceStream();
                if (!inputStream.markSupported()) {
                    inputStream = new BufferedInputStream(inputStream);
                }
                inputStream.mark(Integer.MAX_VALUE); //we can process at maximum 2G with the standard jdk streams

                try {
                    Transformer transformer = buildTransformerChain(digestOutputStream, signaturePartDef, null);

                    Map<String, Object> transformerProperties = new HashMap<String, Object>(2);
                    transformerProperties.put(
                            AttachmentContentSignatureTransform.ATTACHMENT, attachment);
                    transformer.setProperties(transformerProperties);
                    transformer.transform(inputStream);
                    transformer.doFinal();

                    digestOutputStream.close();

                    //reset the inputStream to be able to reuse it
                    inputStream.reset();
                } catch (IOException e) {
                    throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_SIGNATURE, e);
                } catch (XMLStreamException e) {
                    throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_SIGNATURE, e);
                }

                String calculatedDigest = new String(Base64.encode(digestOutputStream.getDigestValue()));
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Calculated Digest: " + calculatedDigest);
                }

                signaturePartDef.setDigestValue(calculatedDigest);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.