/** * 异或加密 * * @param strOld * 源字符串 * @param strKey * 密钥 * @return 加密后的字符串 */ public static String encrypt(String strOld, String strKey) { byte[] data = strOld.getBytes(); byte[] keyData = strKey.getBytes(); int keyIndex = 0; for (int i = 0; i < strOld.length(); i++) { data[ i] = ( byte) ( data[ i] ^ keyData[ keyIndex]); if (++ keyIndex == keyData. length) { keyIndex = 0; } } return new String(data); }
时间: 2024-10-31 18:38:26