MD5.SHA.BASE64算法加解密

package com.wpf.wz;

import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;

public class Base64Demo {

	private static byte[] decryptBASE64(String key) throws IOException {
		return (new BASE64Decoder()).decodeBuffer(key);   
	}
	
	private static String encryptBASE64(byte[] key){
		return (new BASE64Encoder()).encodeBuffer(key);
	}
	
	private static byte[] encryptSHA(byte[] key) throws NoSuchAlgorithmException{
		MessageDigest sha = MessageDigest.getInstance("SHA");
		sha.update(key);
		
		return sha.digest();
	}
	
	private static byte[] encryptMD5(byte[] key) throws NoSuchAlgorithmException{
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		md5.update(key);
		return md5.digest();
	}
	public static void main(String[] args) throws NoSuchAlgorithmException {
		try {
			byte[] bytes = "简单加密".getBytes();

			String en = encryptBASE64(bytes);
			System.out.println("BASE64 加密" + en);
			byte[] out = decryptBASE64(en);
			System.out.println("BASE64解密" + new String(out));
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println(new BigInteger(encryptSHA("SHA简单加密".getBytes())).toString(32));
		System.out.println(new BigInteger(encryptMD5("MD5简单加密".getBytes())).toString(16));
	}
}


测试结果:

BASE64 加密vPK1pbzTw9w=

BASE64解密简单加密
eah5asjrlct2dp9l1mk9qeabi8ut9kbp
-1c32af8f7100e533911c105cfba7840e


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值