Package java.security

Examples of java.security.DigestInputStream


    long received = 0;
    MessageDigest digester = null;
    if (getChecksum) {
      digester = MD5Hash.getDigester();
      stream = new DigestInputStream(stream, digester);
    }
    boolean finishedReceiving = false;

    List<FileOutputStream> outputStreams = Lists.newArrayList();
View Full Code Here


      //
      // Load in bits
      //
      MessageDigest digester = MD5Hash.getDigester();
      DigestInputStream fin = new DigestInputStream(
           new FileInputStream(curFile), digester);

      DataInputStream in = new DataInputStream(fin);
      try {
        // read image version: first appeared in version -1
View Full Code Here

                    // prevent that rs.close() is called again
                    rs = null;
                }
            }
            MessageDigest digest = getDigest();
            DigestInputStream dIn = new DigestInputStream(stream, digest);
            CountingInputStream in = new CountingInputStream(dIn);
            StreamWrapper wrapper;
            if (STORE_SIZE_MINUS_ONE.equals(storeStream)) {
                wrapper = new StreamWrapper(in, -1);
            } else if (STORE_SIZE_MAX.equals(storeStream)) {
View Full Code Here

            /* Computing message digest for the file */
            md = MessageDigest.getInstance(alg);
            FileInputStream fin = new FileInputStream(file);
            BufferedInputStream bin = new BufferedInputStream(fin, BUFSIZE);
            DigestInputStream in = new DigestInputStream(bin, md);
            in.on(true);
            byte[] buf = new byte[BUFSIZE];
            byte[] mdbyte = new byte[BUFSIZE];

            while (true) {
                int n = in.read(buf, 0, buf.length);

                if (n < 0) {
                    break;
                }
            }
            md = in.getMessageDigest();
            mdbyte = md.digest();
            return digestString(mdbyte);
        }
View Full Code Here

            } catch (Exception e) {
                md = MessageDigest.getInstance(ALG);
            }
            FileInputStream fin = new FileInputStream(fileObj);
            BufferedInputStream bin = new BufferedInputStream(fin, BUFSIZE);
            DigestInputStream in = new DigestInputStream(bin, md);
            in.on(true);
            byte[] buf = new byte[BUFSIZE];
            byte[] mdbyte = new byte[BUFSIZE];

            while (true) {
                int n = in.read(buf, 0, buf.length);

                if (n < 0) {
                    break;
                }
            }
            md = in.getMessageDigest();
            mdbyte = md.digest();
            return digestString(mdbyte);
        }
View Full Code Here

    protected static String getSHA(StringBuffer primaryXML) throws NoSuchAlgorithmException, IOException {
        // Note:  For RHEL6 this may need to change to "SHA-256",
        // going for SHA for now, as it's a lowest common denominator so it can work with older clients.
        MessageDigest md = MessageDigest.getInstance("SHA");
        ByteArrayInputStream bis = new ByteArrayInputStream(primaryXML.toString().getBytes());
        DigestInputStream mdistr = new DigestInputStream(bis, md);
        while (mdistr.read() != -1) {
            ;
        }
        mdistr.close();
        return Hex.encodeHexString(md.digest());
    }
View Full Code Here

        }
    }

    private String calculateDigest() throws Exception {
        MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
        DigestInputStream in = null;
       
        try {
            in = new DigestInputStream(new FileInputStream(fileToBeCheckedLocation), messageDigest);
            byte[] buffer = new byte[4096];
            while (in.read(buffer) != -1) {
            }
        } finally {
            StreamUtil.safeClose(in);
        }
       
View Full Code Here

     * @throws Exception On all errors.
     */
    String sha(InputStream istr) throws Exception {
        byte[] bfr = new byte[10240];
        MessageDigest md = MessageDigest.getInstance("SHA");
        DigestInputStream mdistr = new DigestInputStream(istr, md);
        while (mdistr.read(bfr) != -1) {
            ;
        }

        mdistr.close();
        byte[] b = md.digest();
        String result = "";
        for (int i = 0; i < b.length; i++) {
            result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
        }
View Full Code Here

                log.error(msg);
                throw new DataStoreException(msg);
            }
            temporaryInUse.add(tempId);
            MessageDigest digest = getDigest();
            DigestInputStream dIn = new DigestInputStream(stream, digest);
            TrackingInputStream in = new TrackingInputStream(dIn);
            StreamWrapper wrapper;
            if (STORE_SIZE_MINUS_ONE.equals(storeStream)) {
                wrapper = new StreamWrapper(in, -1);
            } else if (STORE_SIZE_MAX.equals(storeStream)) {
View Full Code Here

    public String addBlob(String tempFilePath) {
        try {
            File file = new File(tempFilePath);
            InputStream in = new FileInputStream(file);
            MessageDigest messageDigest = MessageDigest.getInstance(HASH_ALGORITHM);
            DigestInputStream din = new DigestInputStream(in, messageDigest);
            long length = file.length();
            try {
                while (true) {
                    int len = din.read(buffer, 0, buffer.length);
                    if (len < 0) {
                        break;
                    }
                }
            } finally {
                din.close();
            }
            ByteArrayOutputStream idStream = new ByteArrayOutputStream();
            idStream.write(TYPE_HASH);
            IOUtils.writeVarInt(idStream, 0);
            IOUtils.writeVarLong(idStream, length);
View Full Code Here

TOP

Related Classes of java.security.DigestInputStream

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.