Search in sources :

Example 1 with Sun

use of sun.security.provider.Sun in project adempiere by adempiere.

the class DigestOfFile method getMD5Hash.

/**
     * Get md5 hash from byte[]
     * @param input
     * @return mdg hash string
     */
public static String getMD5Hash(byte[] input) {
    String hash;
    java.security.Security.addProvider(new Sun());
    try {
        DigestOfFile md5DigestAgent = new DigestOfFile("MD5");
        hash = md5DigestAgent.digestAsBase64(input);
        return hash;
    } catch (Exception e) {
        //if there is an error during comparison return files are difs
        return null;
    }
}
Also used : Sun(sun.security.provider.Sun)

Example 2 with Sun

use of sun.security.provider.Sun in project adempiere by adempiere.

the class DigestOfFile method GetLocalMD5Hash.

/**
     * @param file
     * @return md5 hash null if file is not found or other error
     */
public static String GetLocalMD5Hash(File file) {
    String hash;
    java.security.Security.addProvider(new Sun());
    try {
        DigestOfFile md5DigestAgent = new DigestOfFile("MD5");
        hash = md5DigestAgent.digestAsBase64(file);
        return hash;
    } catch (Exception e) {
        //if there is an error during comparison return files are difs
        return null;
    }
}
Also used : Sun(sun.security.provider.Sun)

Example 3 with Sun

use of sun.security.provider.Sun in project adempiere by adempiere.

the class DigestOfFile method md5localHashCompare.

/**
     * @param file1 first file to compare
     * @param file2 second file to compare
     * @return true if files are identic false otherwise
     */
public static boolean md5localHashCompare(File file1, File file2) {
    //compute Hash of exisiting and downloaded
    String hashFile1;
    String hashFile2;
    java.security.Security.addProvider(new Sun());
    try {
        DigestOfFile md5DigestAgent = new DigestOfFile("MD5");
        hashFile1 = md5DigestAgent.digestAsBase64(file1);
        hashFile2 = md5DigestAgent.digestAsBase64(file2);
        return hashFile1.equals(hashFile2);
    } catch (Exception e) {
        //if there is an error during comparison return files are difs
        return false;
    }
}
Also used : Sun(sun.security.provider.Sun)

Example 4 with Sun

use of sun.security.provider.Sun in project adempiere by adempiere.

the class DigestOfFile method main.

/**
     * @author rlemeill
     * @param args file
     */
public static void main(String[] args) {
    try {
        java.security.Security.addProvider(new Sun());
        DigestOfFile md5DigestAgent = new DigestOfFile("MD5");
        for (int argIndex = 0; argIndex < args.length; argIndex++) {
            {
                String base64Digest = md5DigestAgent.digestAsBase64(new File(args[argIndex]));
                System.out.println("Base64 MD5 of " + args[argIndex] + " = [" + base64Digest + "]");
            }
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : Sun(sun.security.provider.Sun) File(java.io.File)

Aggregations

Sun (sun.security.provider.Sun)4 File (java.io.File)1