Java SHA shaFile(String paramString)

Here you can find the source of shaFile(String paramString)

Description

sha File

License

Open Source License

Declaration

public static String shaFile(String paramString) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;

import java.security.MessageDigest;

public class Main {
    private static final char[] HEX_DIGITS = { 48, 49, 50, 51, 52, 53, 54,
            55, 56, 57, 97, 98, 99, 100, 101, 102 };

    public static String shaFile(String paramString) {
        byte[] arrayOfByte = new byte[1024];
        try {/*from   w w  w  . j  a  v a  2s  .c  o m*/
            FileInputStream localFileInputStream = new FileInputStream(
                    paramString);
            MessageDigest localMessageDigest = MessageDigest
                    .getInstance("SHA-1");
            while (true) {
                int i = localFileInputStream.read(arrayOfByte);
                if (i <= 0) {
                    localFileInputStream.close();
                    return toHexString(localMessageDigest.digest());
                }
                localMessageDigest.update(arrayOfByte, 0, i);
            }
        } catch (Exception localException) {
        }
        return "";
    }

    public static String toHexString(byte[] paramArrayOfByte) {
        if (paramArrayOfByte == null)
            return "";
        StringBuilder localStringBuilder = new StringBuilder(
                paramArrayOfByte.length << 1);
        for (int i = 0;; i++) {
            if (i >= paramArrayOfByte.length)
                return localStringBuilder.toString();
            localStringBuilder
                    .append(HEX_DIGITS[((0xF0 & paramArrayOfByte[i]) >>> 4)]);
            localStringBuilder
                    .append(HEX_DIGITS[(0xF & paramArrayOfByte[i])]);
        }
    }
}

Related

  1. sha2(String input)
  2. sha2(String password)
  3. sha2(String... data)
  4. sha5Encode(byte[] content)
  5. SHA_1(byte[] input)
  6. SHAHash(byte[] input)
  7. shaHash(String message)
  8. shaPsw(String inputText)
  9. SHAsum(byte[] convertme)