package com.antcorp.anto.database;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.antcorp.anto.widget.MyLog;


public class SimpleSHA1 
{
	public static String sha1Hash(String toHash) 
	{
		String hash = null;
		try {
			MessageDigest digest = MessageDigest.getInstance("SHA-1");
			byte[] bytes = toHash.getBytes("UTF-8");
			
			digest.update(bytes, 0, bytes.length);
			bytes = digest.digest();
			
			StringBuilder sb = new StringBuilder();
			for (byte b : bytes) {
				sb.append(String.format("%02X", b));
			}
			
			hash = sb.toString();
		} catch (NoSuchAlgorithmException e) {
			MyLog.i(e.getMessage());
		} catch (UnsupportedEncodingException e) {
			MyLog.i(e.getMessage());
		}
		
		return hash;
	}
}
