MD5加密

1、md5加密是对字符或密码进行的16位或32位等加密方式! 一般在普通MDB数据库百经常用到,比如论坛数据库等有用!
2、加密解密并不矛盾,比如银行系统的128位加密现在谁可以轻易破的了呢,虽然md5加密不算很难回破,但一般也是穷破法,如果密码不是过于简单的话,那么就很难破(使用工具)!比如密码为 dafsd63f43t5#$! 这样的密码经过md5加密之后就形成了一段密文.用穷破法的话这样一个密码也许要用几年的时间才可以破开!

当然以上这段废话可能大家听起来是很抽象的,那就不如实践一下!
MD5加密的使用
首先需要在pom.xml中添加相应的包依赖

commons-codec
commons-codec
1.12

package com.whc.wznoteserver2.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.codec.digest.DigestUtils;

public class TestMD5 {

public static void main(String[] args) {
	String salt = "!@#";
	String content=readFileByBytes("C:\\Users\\Administrator\\Desktop\\2.txt");
	String md5 = DigestUtils.md5Hex(content);
	System.out.println(md5);
	//4aa1d36a56eb1884e2906ec376311c99--正确的md5
}
private static String md5(String mm,String salt) {
	return DigestUtils.md5Hex(mm+salt);
}
/**
 * 从文件读取内容
 * @param fileName
 * @return
 */
public static String readFileByBytes(String fileName) {
	StringBuffer sb = new StringBuffer();
	try {
		File file = new File(fileName);
		InputStream in = null;
		
		if(file.isFile() && file.exists()) {//判断文件是否存在
			//System.out.println("以字节为单位读取文件内容,一次读取多个字节");
			//一次读多个字节
			byte[] tempbytes = new byte[1024];
			int byteread = 0;
			in = new FileInputStream(file);
			//读入多个字节到字节数组中,byteread为一次读入的字节数
			while((byteread = in.read(tempbytes))!=-1) {
				//System.out.write(tempbytes,0,byteread);
				String str = new String(tempbytes,0,byteread);
				sb.append(str);
			}
		}
	}catch(Exception e) {
		
	}finally {
		return sb.toString();
	}
}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值