Java back-end authoring MD5 encryption

Source: Internet
Author: User
Tags md5 encryption

Due to the need of a business, I made a password modification sub-business.

When the user forgets the password, I need to send him a 6-bit random password, via instant Messenger, SMS, etc. And at the same time modify the original password in the database for this 6-bit random password. Ask the user to change the password again.

At the same time the password in the database must be stored as ciphertext, so you need to use to MD5 encryption. The generated 6-bit random password needs to be kept secret and cannot be processed in the foreground, only on the backend. So I chose to put it in the control layer.

//Pass in any text that needs to be encrypted Public Staticstring GetMd5 (String string) {Try{messagedigest MD= Messagedigest.getinstance ("MD5");            Md.update (String.getbytes ()); byteHash[] =md.digest (); StringBuffer SB=NewStringBuffer (); inti = 0;  for(intoffset = 0; Offset < hash.length; offset++) {i=Hash[offset]; if(I < 0) {i+ = 256; }                if(I < 16) {sb.append ("0");            } sb.append (Integer.tohexstring (i)); }            returnsb.tostring (); }        Catch(nosuchalgorithmexception e) {Throw NewRuntimeException (e); }    }

The 32-bit encryption is used here, and the difference between 16-bit and 32-bit is that 16 bits are 32 bits in the middle of 16 bits.

String Password_ = string.valueof ((int) (Math.random () * 1000000)); if(Empservice.updateemppassword (Emp_id_, Baseutils.getmd5 (Password_), operator) = = 0) {                Throw NewRuntimeException ("Random password generation failed!") "); } String Xele= "<SendMessage><AM_Name>" + Emp_code_ + "</am_name><phonenum></phonenum><userid ></UserId><MessageTxt> your document management system new password is: "+ password_ +" </MessageTxt><SystemName> Document management System < /systemname><type> Instant Messenger </type><access></access><email></email><isback ></isback><isencrypt></isencrypt><ispriority></ispriority><ohter1></ Ohter1><ohter2></ohter2></sendmessage><br/> ";

Then invoke the instant-pass reserved interface

null, operator);

Mainly look at the Java backend how to do MD5 encryption!!

Welcome everyone to read, a lot of comments on the shortcomings!!

For the engineer's road to building blocks!!

Java back-end authoring 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.