zoukankan      html  css  js  c++  java
  • MD5加密(相同的字符串,每次加密后的密文是相同的)

     1 package com.cy.vcard.common.utils;
     2 
     3 import java.math.BigInteger;
     4 import java.security.MessageDigest;
     5 import java.security.NoSuchAlgorithmException;
     6 
     7 import org.springframework.util.StringUtils;
     8 
     9 
    10 
    11 public class MD5Utils {
    12     /**
    13      * 对字符串进行Md5加密
    14      * 
    15      * @param input 原文
    16      * @return md5后的密文
    17      */
    18     public static String md5(String input) {
    19         byte[] code = null;
    20         try {
    21             code = MessageDigest.getInstance("md5").digest(input.getBytes());
    22         } catch (NoSuchAlgorithmException e) {
    23             code = input.getBytes();
    24         }
    25         BigInteger bi = new BigInteger(code);
    26         return bi.abs().toString(32).toUpperCase();
    27     }
    28     
    29     /**
    30      * 对字符串进行Md5加密
    31      * 
    32      * @param input 原文
    33      * @param salt 随机数
    34      * @return string
    35      */
    36     public static String generatePasswordMD5(String input, String salt) {
    37         if(StringUtils.isEmpty(salt)) {
    38             salt = "";
    39         }
    40         return md5(salt + md5(input));
    41     }
    42     
    43     public static void main(String[] args) {
    44         System.out.println(md5("111111"));
    45     }
    46     
    47 }
  • 相关阅读:
    Python保留最后N个元素
    STL算法
    STL迭代器
    STL容器
    C++总结1
    牛客剑指Offer2
    Vue第一天
    UML
    Java继承和组合代码
    Java15后的sealed阻止继承滥用
  • 原文地址:https://www.cnblogs.com/wdpnodecodes/p/8001613.html
Copyright © 2011-2022 走看看