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);
}
}

發佈了123 篇原創文章 · 獲贊 350 · 訪問量 99萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章