最近在做Android的逆向分析,我主要是负责网络请求的逆向分析,在分析的过程中必然会碰到数据加解密的过程。其中最常见的加解密就是异或。
异或加密是数据加密中比较简单的一种,也是比较常用的一种方法。
所谓异或就是一种位运算,比如1^1=0;1^0=1,也就是两个运算位为同为“1”或“0”则返回“0”,若两个运算位不同为“1”或“0”则返回“1”。
算了,说多无用,直接代码:
public class Xor {
public static void main(String[] args) {
// TODO Auto-generated method stub
String data="hello world";
System.out.println("------------原文--------------");
System.out.println(data);
String after=new String(xorEncode(data.getBytes()));
System.out.println("------------加密--------------");
System.out.println(after);
String before=new String(xorEncode(after.getBytes()));
System.out.println("------------解密---------------");
System.out.println(before);
}
public static byte[] xorEncode(byte[] data){
//key,用于异或
String key="TheK