/**
*
* @author comtu
* @version 编写时间: 2013-5-7上午11:22:56
*/
@Test
public void testAs2() {
// 需要加密的数据
String str = "中国你好001_abcd+3542398=-=-*(&^*&%!@$*";
System.out.println("需要加密的数据:" + str);
// 加密密钥
int ranNumKey = randomNumKey();
System.out.println("加密密钥" + ranNumKey);
// 加密前的byte
byte[] b = str.getBytes();
Long lStart = System.currentTimeMillis();
// 加密后的byte
byte[] b2 = encryptionDeciphering(ranNumKey, b);
// 解密后的byte
byte[] b3 = encryptionDeciphering(ranNumKey, b2);
String strb3 = new String(b3);
System.out.println("解密后的数据:" + strb3);
Long lEnd = System.currentTimeMillis();
System.out.println(lEnd - lStart);
}
/**
* 加密_解密
*
* @param ranNumKey
* @param b
* @return
*/
private byte[] encryptionDeciphering(int ranNumKey, byte[] b) {
byte[] b2 = new byte[b.length];
for (int i = 0; i < b.length; i++) {
b2[i] = (byte) (b[i] ^ ranNumKey);
}
return b2;
}
/**
* 产生随机数
*
* @return
*/
private int randomNumKey() {
return (int) Math.floor((Math.random() * Integer.MAX_VALUE));
}