当前位置:首页 > 生活百科

md5工具使用方法(修改md5值的软件推荐)

栏目:生活百科日期:2025-05-18浏览:0

0x01:工具类

md5加密工具类base64加密工具类Bcrypt工具类

0x02:加密测试

MD5加密测试base64加密测试SHA加密测试BCrypt加密测试

0x03、工具类

1. md5加密工具类
public class MD5Utils {private static final String hexDigIts&[] = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};/**     * MD5加密     * @param origin 字符     * @param charsetname 编码     * @return     */public static String MD5Encode(String origin, String charsetname){        String resultString = null;try{            resultString = new String(origin);            MessageDigest md = MessageDigest.getInstance("MD5");if(null == charsetname || "".equals(charsetname)){                resultString = byteArrayToHexString(md.digest(resultString.getBytes()));            }else{                resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname)));            }        }catch (Exception e){        }return resultString;    }public static String byteArrayToHexString(byte b&[]){        StringBuffer resultSb = new StringBuffer();for(int i = 0; i &< b.length; i++){            resultSb.append(byteToHexString(b&[i]));        }return resultSb.toString();    }public static String byteToHexString(byte b){int n = b;if(n &< 0){            n += 256;        }int d1 = n / 16;int d2 = n % 16;return hexDigIts&[d1] + hexDigIts&[d2];    }}
2. base64加密工具类
public class Base64Util {// 字符串编码private static final String UTF_8 = "UTF-8";/**     * 加密字符串     * @param inputData     * @return     */public static String decodeData(String inputData) {try {if (null == inputData) {return null;            }return new String(Base64.decodeBase64(inputData.getBytes(UTF_8)), UTF_8);        } catch (UnsupportedEncodingException e) {        }return null;    }/**     * 解密加密后的字符串     * @param inputData     * @return     */public static String encodeData(String inputData) {try {if (null == inputData) {return null;            }return new String(Base64.encodeBase64(inputData.getBytes(UTF_8)), UTF_8);        } catch (UnsupportedEncodingException e) {        }return null;    }public static void main(String&[] args) {        System.out.println(Base64Util.encodeData("我是中文"));String enStr = Base64Util.encodeData("我是中文");        System.out.println(Base64Util.decodeData(enStr));    }}
3. Bcrypt工具类
public class BcryptCipher {// generate salt seedprivate static final int SALT_SEED = 12;// the head fo saltprivate static final String SALT_STARTSWITH = "$2a$12";public static final String SALT_KEY = "salt";public static final String CIPHER_KEY = "cipher";/**   * Bcrypt encryption algorithm method   * @param encryptSource   * need to encrypt the string   * @return Map , two values in Map , salt and cipher   */public static Map&<String, String&> Bcrypt(final String encryptSource) {String salt = BCrypt.gensalt(SALT_SEED);    Map&<String, String&> bcryptResult = Bcrypt(salt, encryptSource);return bcryptResult;  }/**   *   * @param salt encrypt salt, Must conform to the rules   * @param encryptSource   * @return   */public static Map&<String, String&> Bcrypt(final String salt, final String encryptSource) {if (StringUtils.isBlank(encryptSource)) {throw new RuntimeException("Bcrypt encrypt input params can not be empty");    }if (StringUtils.isBlank(salt) || salt.length() != 29) {throw new RuntimeException("Salt can't be empty and length must be to 29");    }if (!salt.startsWith(SALT_STARTSWITH)) {throw new RuntimeException("Invalid salt version, salt version is $2a$12");    }String cipher = BCrypt.hashpw(encryptSource, salt);    Map&<String, String&> bcryptResult = new HashMap&<String, String&>();    bcryptResult.put(SALT_KEY, salt);    bcryptResult.put(CIPHER_KEY, cipher);return bcryptResult;  }}

0x04:加密测试

1. MD5加密测试
/** * MD5加密 */public class MD5Test {public static void main(String&[] args) {    String string = "我是一句话";    String byteArrayToHexString = MD5Utils.byteArrayToHexString(string.getBytes());    System.out.println(byteArrayToHexString);//e68891e698afe4b880e58fa5e8af9d  }}
2. base64加密测试
/** * base64加密 */public class Bast64Tester {public static void main(String&[] args) {    String string = "我是一个字符串";    String encodeData = Base64Util.encodeData(string); //加密    String decodeData = Base64Util.decodeData(encodeData); //解密    System.out.println(encodeData);//5oiR5piv5LiA5Liq5a2X56ym5Liy    System.out.println(decodeData);//我是一个字符串}}
3. SHA加密测试
/** * SHA加密 */public class ShaTest {public static void main(String&[] args) {    String string = "我是一句话";    String sha256Crypt = Sha2Crypt.sha256Crypt(string.getBytes());    System.out.println(sha256Crypt);//$5$AFoQTeyt$TiqmobvcQXjXaAQMYosAAO4KI8LfigZMGHzq.Dlp4NC  }}
4. BCrypt加密测试
/** * BCrypt加密 */public class BCryptTest {public static void main(String&[] args

“md5工具使用方法(修改md5值的软件推荐)” 的相关文章

iphone6plus屏幕尺寸多大(各屏幕尺寸及解析)

大家都知道,现在苹果已经不再是之前的苹果了,价格一年比一年贵,而且保值率也没有以往那么稳了,基本上新款机型发布后,过不了几个月都会出现价格松动的现象。不过今天的...

seo好做吗,seo工作前景分析

1.搜索引擎算法不断更新搜索引擎发展到现在,几乎每天都在完善自己的漏洞,放在以前,我们发发外链更新一下文章,就能获取一个不错的排名;而对于目前而言,搜索引擎更看...

国外seo优化工具有哪些,国外搜索引擎优化的思路

工欲善其事,必利其器,在工具性能上来说国内外的SEO优化工具总是有少许差别,尽管对于大部分网站优化工作还得靠人工去做,但SEO工具作为辅助工具,是站长都应该必须...

aso关键词排名优化是什么,aso关键词优化工具盘点

先让我们来重温一下ASO优化是什么?ASO是AppStoreOptimization的缩写,即应用商店优化。就是通过对App做一系列的优化手段,以提升其在App...

idea类注释模板快捷键(idea自动生成方法注释快捷键)

Java的注释有2种//.和/*&…*/IntelliJIDEA可以使用下面的快捷键来对代码进行注释:Ctrl+/:for单行注释(//…)Ctrl...

2023年上半年手机销量排行榜(中国手机销量排行榜最新)

前段时间国外知名行业分析机构StrategyAnalytics,预测了2021年全球手机品牌销量排名,第一名三星,第二名苹果,第三名小米,vivo和OPPO排名...

winrar最新版怎么去广告(屏蔽winrar弹窗广告的方法)

软件版本:软件大小:软件授权:经常使用winrar的用户都知道,自从升级或下载Winrar最新版后,我们在打开rar、zip、7z等压缩格式文件时会出现弹屏广告...

京东商城入驻条件和费用(京东入驻类目费用表)

随着网购的平台逐渐增多,各大网购平台的优劣势也是慢慢浮现出来,以最为明显的淘宝和天猫来做比较,淘宝或许就像是一个大集市,而天猫则像是一个大商场,虽然都是一家平台...

创业网站有哪些好项目,中国创业第一门户网站

适合年轻人的创业项目,只有先了解了,才能让你有机会赚!适合年轻人创业项目,投资少,回报快!吃获日记为大家归纳了两个外卖市场的新兴项目,希望对你有帮助。一、外卖代...

shell脚本语言的优势(shell脚本基本语法)

4.1条件选择4.1.1选择执行if语句格式:ifCOMMANDS;thenCOMMANDS;&[elifCOMMANDS;thenCOMMANDS;]...