Package java.security

Examples of java.security.DigestOutputStream


            usesIdentifier(tempId);
            // Copy the stream to the temporary file and calculate the
            // stream length and the message digest of the stream
            long length = 0;
            MessageDigest digest = MessageDigest.getInstance(DIGEST);
            OutputStream output = new DigestOutputStream(
                    new FileOutputStream(temporary), digest);
            try {
                length = IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            DataIdentifier identifier = new DataIdentifier(digest.digest());
            File file;

            synchronized (this) {
View Full Code Here


    }

    private static String writeMF(File dir, Manifest manifest, ZipOutputStream zos) throws NoSuchAlgorithmException,
            IOException {
        MessageDigest md = MessageDigest.getInstance("SHA1");
        DigestOutputStream dos = new DigestOutputStream(zos, md);
        zipAndSha1(dir, zos, dos, manifest);
        Attributes main = manifest.getMainAttributes();
        main.putValue("Manifest-Version", "1.0");
        main.putValue("Created-By", "tiny-sign-" + TinySign.class.getPackage().getImplementationVersion());
        zos.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
View Full Code Here

        return new String(Base64.encodeBase64(data));
    }

    private static Manifest generateSF(Manifest manifest) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance("SHA1");
        PrintStream print = new PrintStream(new DigestOutputStream(new OutputStream() {

            @Override
            public void write(byte[] arg0) throws IOException {
            }
View Full Code Here

            if (withIntegrityPacket)
            {
                String digestName = PGPUtil.getDigestName(HashAlgorithmTags.SHA1);
                MessageDigest digest = MessageDigest.getInstance(digestName, defProvider);
                genOut = digestOut = new DigestOutputStream(cOut, digest);
            }

            byte[] inLineIv = new byte[c.getBlockSize() + 2];
            rand.nextBytes(inLineIv);
            inLineIv[inLineIv.length - 1] = inLineIv[inLineIv.length - 3];
View Full Code Here

    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

        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

        digest = MessageDigest.getInstance("MD5");
      } catch (NoSuchAlgorithmException e) {
        throw (IOException) (new IOException("No MD5 implementation")
        .initCause(e));
      }
      DigestOutputStream digestStream = new DigestOutputStream(
          new NullOutputStream(), digest);
      PrintWriter pw = new PrintWriter(digestStream);
      String line;
      String existingMD5 = null;
      while ((line = br.readLine()) != null) {
        if (line.startsWith(MD5_LINE_PART_1)) {
          existingMD5 = line.replaceAll(MD5_LINE_PART_1q, "").replaceAll(
              MD5_LINE_PART_2q, "");
        } else {
          pw.println(line);
        }
      }

      pw.close();
      String calculatedDigest = toHexString(digestStream
          .getMessageDigest().digest());

      if (existingMD5 == null || !existingMD5.equals(calculatedDigest)) {
        // No checksum in file, or checksum differs.
        needToWrite = false;
View Full Code Here

        }
        OutputStream base;
        if (digest == null) {
            base = new FileOutputStream(localFile);
        } else {
            base = new DigestOutputStream(
                    new FileOutputStream(localFile), digest);
        }
        if (lineFeed != null) {
            base = new LineOutputStream(base, lineFeed);
        }
View Full Code Here

      try {
        OutputStream out = fOut;
        if (config.getFSyncObjectFiles())
          out = Channels.newOutputStream(fOut.getChannel());
        DeflaterOutputStream cOut = compress(out);
        DigestOutputStream dOut = new DigestOutputStream(cOut, md);
        writeHeader(dOut, type, len);

        final byte[] buf = buffer();
        while (len > 0) {
          int n = is.read(buf, 0, (int) Math.min(len, buf.length));
          if (n <= 0)
            throw shortInput(len);
          dOut.write(buf, 0, n);
          len -= n;
        }
        dOut.flush();
        cOut.finish();
      } finally {
        if (config.getFSyncObjectFiles())
          fOut.getChannel().force(true);
        fOut.close();
View Full Code Here

            usesIdentifier(tempId);
            // Copy the stream to the temporary file and calculate the
            // stream length and the message digest of the stream
            long length = 0;
            MessageDigest digest = MessageDigest.getInstance(DIGEST);
            OutputStream output = new DigestOutputStream(
                    new FileOutputStream(temporary), digest);
            try {
                length = IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            DataIdentifier identifier = new DataIdentifier(digest.digest());
            File file;

            synchronized (this) {
View Full Code Here

TOP

Related Classes of java.security.DigestOutputStream

Copyright © 2018 www.massapicom. 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.