UUID, the use of cryptographic decryption algorithms

Source: Internet
Author: User
Tags decrypt md5 encryption

Note the place:

Base64encoder,base64decoder is not part of the JDK standard library category, but is also included in the JDK

Workaround: Set the Rt.jar package under Eclipse import%java_home%\jre\lib directory as follows, Project->properties, select the JAVA Build path setting, Then choose the libraries tag, add External jars added%java_home%\jre\lib\rt.jar can be used!

If you encounter this situation when you use Base64decoder:access restriction:the type Base64decoder is not accessible due to restriction on require D Library C:\Program
Files\java\jre6\lib\rt.jar , you only need to remove the JRE system library in project build path, and then add the Library JRE system library.

The specific code is as follows:

Package Leetcode;import Java.io.ioexception;import Java.math.biginteger;import java.security.messagedigest;import Java.security.nosuchalgorithmexception;import Java.util.uuid;import Sun.misc.base64decoder;import Sun.misc.base64encoder;public class Test12 {public static string GetId () {//uuid Java does not repeat the sequence String id = uuid.randomuuid (). ToString ();//system.out.println (ID);//The serial number obtained is very long and can be represented by a hash code of int hashcode = Math.Abs (Id.hashcode ()); return hashcode+ " ";} MD5 encryption algorithm, one-way encryption, no decrypted public static string MD5 (String str) {byte[] bytes = null;try {bytes = messagedigest.getinstance ("MD5 "). Digest (Str.getbytes ());//Get an instance of MD5, and then encrypt the string} catch (NoSuchAlgorithmException e) {e.printstacktrace ();} return new BigInteger (1,bytes). toString (16);//convert byte array to positive BigInteger, then 16 binary representation}//base64 algorithm, decrypt, encrypt public static String Base64Encode (String str) {Base64encoder Baseencode = new Base64encoder (); return Baseencode.encode (Str.getbytes ());// Encrypt}public static string Base64decode (String str) {Base64decoder Basedecoder = new Base64decoder (); try {return new String (Basedecoder.decodebuffer (str));//Decrypt} catch (IOException e) {e.printstacktrace ();} return null;} public static void Main (string[] args) {System.out.println (GetId ()); SYSTEM.OUT.PRINTLN ("1234 after encryption:" +MD5 ("1234")); String str = base64encode ("1234"); SYSTEM.OUT.PRINTLN ("1234 after encryption:" +STR); System.out.println ("After decryption:" +base64decode (str));}}

The results of the operation are as follows:

888859973
1234 after encryption: 81dc9bdb52d04dc20036dbd8313ed055
1234 after encryption: mtizna==
After decryption: 1234

UUID, the use of cryptographic decryption algorithms

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.