Implementing encryption using Java's own: reference https://jingyan.baidu.com/article/2fb0ba40a2ef2b00f3ec5f74.html
/*** Implementation of SHA256 encryption with Java Native Digest *@paramSTR Encrypted message *@return */ Public Staticstring Getsha256strjava (String str) {MessageDigest messagedigest; String Encodestr= ""; Try{messagedigest= Messagedigest.getinstance ("SHA-256"); Messagedigest.update (Str.getbytes ("UTF-8")); Encodestr=Byte2hex (Messagedigest.digest ()); } Catch(nosuchalgorithmexception e) {e.printstacktrace (); } Catch(unsupportedencodingexception e) {e.printstacktrace (); } returnEncodestr; } /*** Convert byte to 16 binary *@parambytes *@return */ Private StaticString Byte2hex (byte[] bytes) {StringBuffer StringBuffer=NewStringBuffer (); String Temp=NULL; for(inti=0;i<bytes.length;i++) {Temp= Integer.tohexstring (Bytes[i] & 0xFF); if(Temp.length () ==1){ //1 Get one bit to make a 0 operationStringbuffer.append ("0"); } stringbuffer.append (temp); } returnstringbuffer.tostring (); }
SHA256---Using Java to implement encryption