This function calculates the SHA1 value of a given string - Java Security

Java examples for Security:SHA

Description

This function calculates the SHA1 value of a given string

Demo Code


//package com.java2s;

import java.security.MessageDigest;

public class Main {
    /**//from ww w .j a va  2 s  . c o m
     * This function calculates the SHA1 value of a given string
     * 
     * @param content
     * @return
     */
    public static byte[] generateSHA(String content) {
        byte[] result = null;
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(content.getBytes());
            result = md.digest();
            md.reset();
        } catch (Exception e) {
            //         Logger.error("generateSHA: " + e.getMessage());
        }
        return result;
    }
}

Related Tutorials