国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

AES加密

2019-11-06 09:53:55
字體:
來源:轉載
供稿:網友

public class AESUtils {	public final static String pwd = "1234567890";	public static String encode(String in) {		String hex = "";		try {			byte[] bytIn = in.getBytes("utf-8");			SecretKeySpec skeySpec = new SecretKeySpec(					pwd .getBytes(), "AES");			Cipher cipher = Cipher.getInstance("AES");			cipher.init(Cipher.ENCRYPT_MODE, skeySpec);			byte[] bytOut = cipher.doFinal(bytIn);			hex = byte2hexString(bytOut);		} catch (NoSuchAlgorithmException e) {			e.PRintStackTrace();		} catch (NoSuchPaddingException e) {			e.printStackTrace();		} catch (InvalidKeyException e) {			e.printStackTrace();		} catch (IllegalBlockSizeException e) {			e.printStackTrace();		} catch (BadPaddingException e) {			e.printStackTrace();		} catch (UnsupportedEncodingException e) {			e.printStackTrace();		}		return hex;	}	public static String decode(String hex)  {		String rr = "";		byte[] bytIn = hex2Bin(hex);		SecretKeySpec skeySpec = new SecretKeySpec(pwd.getBytes(),				"AES");		Cipher cipher;		try {			cipher = Cipher.getInstance("AES");			cipher.init(Cipher.DECRYPT_MODE, skeySpec);			byte[] bytOut = cipher.doFinal(bytIn);			rr = new String(bytOut, "utf-8");		} catch (NoSuchAlgorithmException e1) {			e1.printStackTrace();		} catch (NoSuchPaddingException e1) {			e1.printStackTrace();		} catch (InvalidKeyException e) {			e.printStackTrace();		} catch (IllegalBlockSizeException e) {			e.printStackTrace();		} catch (BadPaddingException e) {			e.printStackTrace();		} catch (UnsupportedEncodingException e) {			e.printStackTrace();		}		return rr;	}	private static byte[] hex2Bin(String src) {		if (src.length() < 1)			return null;		byte[] encrypted = new byte[src.length() / 2];		for (int i = 0; i < src.length() / 2; i++) {			int high = Integer.parseInt(src.substring(i * 2, i * 2 + 1), 16);			int low = Integer.parseInt(src.substring(i * 2 + 1, i * 2 + 2), 16);			encrypted[i] = (byte) (high * 16 + low);		}		return encrypted;	}	private static String byte2hexString(byte buf[]) {		StringBuffer strbuf = new StringBuffer(buf.length * 2);		int i;		for (i = 0; i < buf.length; i++) {			strbuf.append(Integer.toString((buf[i] >> 4) & 0xf, 16)					+ Integer.toString(buf[i] & 0xf, 16));		}		return strbuf.toString();	}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 健康| 彰化县| 青浦区| 马尔康县| 林口县| 古交市| 武隆县| 贺兰县| 尼勒克县| 哈尔滨市| 亚东县| 乌审旗| 宣城市| 玉林市| 会昌县| 锡林郭勒盟| 平乡县| 沂源县| 临江市| 高雄县| 兰考县| 新河县| 临汾市| 西乌珠穆沁旗| 徐汇区| 寿光市| 子长县| 于都县| 普兰店市| 哈密市| 沂源县| 峨眉山市| 永定县| 衡山县| 垫江县| 房山区| 清丰县| 江口县| 蛟河市| 启东市| 宜章县|