java汉字加密解密

来源:互联网 发布:时时彩定位一码计算法 编辑:程序博客网 时间:2024/06/05 13:32
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);
}
}
原创粉丝点击