java和mysql中md5+base64的执行结果
生活随笔
收集整理的這篇文章主要介紹了
java和mysql中md5+base64的执行结果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 前言
- java md5+base64
- java md5+base64:commons-codec
- java md5+base64:shiro-core
- java covertToString(md5)+base64
- java covertToString(md5)+base64:commons-codec
- mysql md5+base64
前言
- jdk1.8
- mysql 5.7
java md5+base64
import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Base64;public class TestMain {public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {String password = "123456";MessageDigest md5 = MessageDigest.getInstance("MD5");md5.update(password.getBytes("UTF8"));byte[] md5Bytes = md5.digest();String base64Str = Base64.getEncoder().encodeToString(md5Bytes);System.out.println(base64Str);} }執行結果:
4QrcOUm6Wau+VuBX8g+IPg==java md5+base64:commons-codec
maven 坐標:
<dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.11</version></dependency>代碼:
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.digest.DigestUtils;public class TestMain {public static void main(String[] args) {String password = "123456";byte[] md5Bytes = DigestUtils.md5(password);String base64Str = Base64.encodeBase64String(md5Bytes);System.out.println(base64Str);} }執行結果:
4QrcOUm6Wau+VuBX8g+IPg==java md5+base64:shiro-core
maven 坐標:
<dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-core</artifactId><version>1.7.1</version></dependency>代碼:
import org.apache.shiro.crypto.hash.Md5Hash;public class TestMain {public static void main(String[] args) {String password = "123456";String base64Str = new Md5Hash(password).toBase64();System.out.println(base64Str);} }執行結果:
4QrcOUm6Wau+VuBX8g+IPg==java covertToString(md5)+base64
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Base64;public class TestMain {public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {String password = "123456";MessageDigest md5 = MessageDigest.getInstance("MD5");md5.update(password.getBytes("UTF8"));byte[] md5Bytes = md5.digest();String md5Str = "";for (int i = 0; i < md5Bytes.length; i++) {md5Str += Integer.toHexString(md5Bytes[i] | 0xFFFFFF00).substring(6);}String base64Str = Base64.getEncoder().encodeToString(md5Str.getBytes(StandardCharsets.UTF_8));System.out.println(base64Str);} }執行結果:
ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=java covertToString(md5)+base64:commons-codec
maven 坐標:
<dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.11</version></dependency>代碼:
import java.nio.charset.StandardCharsets; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.digest.DigestUtils;public class TestMain {public static void main(String[] args) {String password = "123456";String md5Str = DigestUtils.md5Hex(password);String base64Str = Base64.encodeBase64String(md5Str.getBytes(StandardCharsets.UTF_8));System.out.println(base64Str);} }執行結果:
ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=mysql md5+base64
mysql> select to_base64(md5('123456')); +----------------------------------------------+ | to_base64(md5('123456')) | +----------------------------------------------+ | ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U= | +----------------------------------------------+ 1 row in set (0.01 sec)總結
以上是生活随笔為你收集整理的java和mysql中md5+base64的执行结果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【若依(ruoyi)】自定义layer
- 下一篇: G1P0什么意思