java汉字加密解密

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;

public class ChineseTrans {
public static void main(String[] args) throws UnsupportedEncodingException {
String Mtext="ninhao!123您好!";
Mtext=java.net.URLEncoder.encode(Mtext,"GBK");
byte ptext[]=Mtext.getBytes("GBK");//将字符串转换成byte类型数组,实质是各个字符的二进制形式
BigInteger m=new BigInteger(ptext);//二进制串转换为一个大整数

byte[]mt=m.toByteArray();//m为密文的BigInteger类型
String str=(new String(mt,"GBK"));
str=java.net.URLDecoder.decode(str,"GBK"); 


System.out.println(str);
}
}

版权声明:本文为henren555原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。