Java String XOR Encode XORencode(String res, String key)

Here you can find the source of XORencode(String res, String key)

Description

XO Rencode

License

Open Source License

Declaration

public static String XORencode(String res, String key) 

Method Source Code

//package com.java2s;

public class Main {
    public static String XORencode(String res, String key) {
        byte[] bs = res.getBytes();
        for (int i = 0; i < bs.length; i++) {
            bs[i] = (byte) ((bs[i]) ^ key.hashCode());
        }//from   ww  w  . ja v a2 s .  c om
        return parseByte2HexStr(bs);
    }

    public static String parseByte2HexStr(byte buf[]) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < buf.length; i++) {
            String hex = Integer.toHexString(buf[i] & 0xFF);
            if (hex.length() == 1) {
                hex = '0' + hex;
            }
            sb.append(hex.toUpperCase());
        }
        return sb.toString();
    }
}

Related

  1. xorEncode(String data, String key)