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