Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21815 amit.gupta 1
package com.spice.profitmandi.common.util;
2
 
3
import java.security.MessageDigest;
4
import java.security.NoSuchAlgorithmException;
5
public class ShaUtil {
6
    public static String hash256(String data) throws NoSuchAlgorithmException {
7
        MessageDigest md = MessageDigest.getInstance("SHA-256");
8
        md.update(data.getBytes());
9
        return bytesToHex(md.digest());
10
    }
11
    public static String bytesToHex(byte[] bytes) {
12
        StringBuffer result = new StringBuffer();
13
        for (byte byt : bytes) result.append(Integer.toString((byt & 0xff) + 0x100, 16).substring(1));
14
        return result.toString();
15
    }
16
}