Apache Commons Codec Jar Pack official
Download the extract and put the Commons-codec-1.9.jar into Lib.
For an introduction to the SHA1 algorithm, see Wiki:http://en.wikipedia.org/wiki/sha-1
Here is a brief introduction to the Apache Commons CODEC implementation of algorithms such as BASE64/MD5/SHA1/SHA256, the code is as follows:
Package com.ricky.java.csv.util;
Import org.apache.commons.codec.binary.Base64;
Import Org.apache.commons.codec.digest.DigestUtils;
public class Encryptionutils {
public static string Base64Encode (string data) {
Return base64.encodebase64string (Data.getbytes ());
}
public static byte[] Base64decode (String data) {
Return Base64.decodebase64 (Data.getbytes ());
}
public static string MD5 (string data) {
return Digestutils.md5hex (data);
}
public static string SHA1 (string data) {
return Digestutils.shahex (data);
}
public static string Sha256hex (string data) {
return Digestutils.sha256hex (data);
}
Maven:
<dependency> <groupId>commons-codec</groupId> <artifactid>commons-codec</ artifactid> <version>1.4</version></dependency>
Apache Commons CODEC encoding and decoding