Apache Commons CODEC encoding and decoding

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.