JAVA32 bit MD5 encryption

Source: Internet
Author: User
Tags md5 encryption

The code is as follows

Import Java.security.MessageDigest;

Import java.security.NoSuchAlgorithmException;


public class Main {


public static void Main (string[] args) {

Main main = new main ();

System.out.println (Main.encryption ("xiaowen123"));

}


/**

*

* @param plaintext

* Clear Text

* @return 32-bit ciphertext

*/

public string encryption (string plaintext) {

String md5 = new string ();

try {

MessageDigest MD = messagedigest.getinstance ("MD5");

Md.update (Plaintext.getbytes ());

byte b[] = Md.digest ();


int i;


StringBuffer buf = new StringBuffer ("");

for (int offset = 0; offset < b.length; offset++) {

i = B[offset];

if (I < 0)

i + = 256;

if (I < 16)

Buf.append ("0");

Buf.append (integer.tohexstring (i));

}


MD5 = buf.tostring ();


} catch (NoSuchAlgorithmException e) {

E.printstacktrace ();

}

return MD5;

}

}

Detailed Description: http://java.662p.com/thread-3792-1-1.html

This article is from the "Java" blog, so be sure to keep this source http://6058287.blog.51cto.com/6048287/1579859

JAVA32 bit MD5 encryption

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.