/** * 加密 * * @param plain 明文 * @param charset 明文字符编码 * @param hexKey 十六进制字符串形式密钥 * @return 十六进制字符串形式密文 * @throws Exception */ public static String encrypt(String plain, String charset, String hexKey) throws Exception { if (plain == null || charset == null || hexKey == null) { return null; } return ByteFormat.toHex(encrypt(plain.getBytes(charset), ByteFormat.hexToBytes(hexKey))); }
public static void main(String args[]) { String plainText = "dffrrereeeeeeeeeeeeeeeeeeeeeeeerererefffrererefffddfdfdfdfdfdfdf343434343434343ffffrerererere;l;l;ll;;l;l;lffffffffff4343434343434343434343ffffffffffffffffffffffffabcdefgddddddddddddddddddddsdssddssdsdsssddsddddddddddddsdsjj111gfgfgfffffff;llklklklklkkhghghghghgkkkkkkkkkkkkkkkkkkhghjffffffffffffffgao"; byte key[] = "GdWb5dnxhUxFKcE4GqdhL23TndZFYXPy".getBytes(); try { long t1 = System.currentTimeMillis(); String cipherText = XXTea.encrypt(plainText, "UTF-8", ByteFormat.toHex(key)); System.out.println(cipherText); String pText = XXTea.decrypt(cipherText, "UTF-8", ByteFormat.toHex(key)); System.out.println(pText); long t2 = System.currentTimeMillis(); System.out.println(t2 - t1); } catch (Exception ex) { ex.printStackTrace(); } }