common_helper/src/main/java/com/xiongyingqi/util/DynamicPassword.java
public byte[] generateCode(byte[] key, int refreshTime) {
        byte[] bs = getTimeBytes(refreshTime);
        int length = bs.length;
        for (int i = 0; i < length; i++) {
            byte b = bs[i];
            for (int j = 0; j < length; j++) {
                bs[i] = (byte) (bs[j] | b);
                bs[i] = (byte) (bs[j] ^ b);
            }
        }

        int keyLength = key.length;
        byte[] rs = new byte[keyLength];
        System.arraycopy(key, 0, rs, 0, keyLength);
        for (int i = 0; i < keyLength; i++) {
            byte k = rs[i];
            for (int j = 0; j < length; j++) {
                rs[i] = (byte) (bs[j] ^ k);
                rs[i] = (byte) (bs[j] | k);
            }
        }
        // String string = Base64.encodeBytes(rs);
        // System.out.println(string);
        return rs;
    }
public byte[] generateCode(byte[] key, int refreshTime) {
        byte[] bs = getTimeBytes(refreshTime);
        int length = bs.length;
        for (int i = 0; i < length; i++) {
            byte b = bs[i];
            for (int j = 0; j < length; j++) {
                bs[i] = (byte) (bs[j] | b);
                bs[i] = (byte) (bs[j] ^ b);
            }
        }

        int keyLength = key.length;
        byte[] rs = new byte[keyLength];
        System.arraycopy(key, 0, rs, 0, keyLength);
        for (int i = 0; i < keyLength; i++) {
            byte k = rs[i];
            for (int j = 0; j < length; j++) {
                rs[i] = (byte) (bs[j] ^ k);
                rs[i] = (byte) (bs[j] | k);
            }
        }
        // String string = Base64.encodeBytes(rs);
        // System.out.println(string);
        return rs;
    }
public byte [ ] generateCode ( byte [ ] key , int refreshTime ) { byte [ ] bs = getTimeBytes ( refreshTime ) ; int length = bs . length ; for ( int i = 0 ; i < length ; i ++ ) { byte b = bs [ i ] ; for ( int j = 0 ; j < length ; j ++ ) { bs [ i ] = ( byte ) ( bs [ j ] | b ) ; bs [ i ] = ( byte ) ( bs [ j ] ^ b ) ; } } int keyLength = key . length ; byte [ ] rs = new byte [ keyLength ] ; System . arraycopy ( key , 0 , rs , 0 , keyLength ) ; for ( int i = 0 ; i < keyLength ; i ++ ) { byte k = rs [ i ] ; for ( int j = 0 ; j < length ; j ++ ) { rs [ i ] = ( byte ) ( bs [ j ] ^ k ) ; rs [ i ] = ( byte ) ( bs [ j ] | k ) ; } } // String string = Base64.encodeBytes(rs); // System.out.println(string); return rs ; }
对字节进行迭代运算，这样结果就不具备规律性
<br>2014-2-11 下午9:14:18

@param key
@return
对字节进行迭代运算，这样结果就不具备规律性 <br > 2014 - 2 - 11 下午9 : 14 : 18