package com.litesuits.common.data.cipher;


import com.litesuits.common.assist.Base64;

/**
 * @author MaTianyu
 * @date 14-7-31
 */
public class Base64Cipher extends Cipher {
    private Cipher cipher;

    public Base64Cipher() {
    }

    public Base64Cipher(Cipher cipher) {
        this.cipher = cipher;
    }

    @Override
    public byte[] decrypt(byte[] res) {
        if(cipher != null) res = cipher.decrypt(res);
        return Base64.decode(res, Base64.DEFAULT);
    }

    @Override
    public byte[] encrypt(byte[] res) {
        if(cipher != null) res = cipher.encrypt(res);
        return Base64.encode(res, Base64.DEFAULT);
    }
}

package com.litesuits.common.data.cipher;


import com.litesuits.common.assist.Base64;

/**
 * @author MaTianyu
 * @date 14-7-31
 */
public class Base64Cipher extends Cipher {
    private Cipher cipher;

    public Base64Cipher() {
    }

    public Base64Cipher(Cipher cipher) {
        this.cipher = cipher;
    }

    @Override
    public byte[] decrypt(byte[] res) {
        if(cipher == null) return Base64.decode(res, Base64.DEFAULT);
        res=Base64.decode(res, Base64.DEFAULT);
        return cipher.decrypt(res);;
    }

    @Override
    public byte[] encrypt(byte[] res) {
        if(cipher != null) res = cipher.encrypt(res);
        return Base64.encode(res, Base64.DEFAULT);
    }
}

修改多次加密失败问题，加密时Base64是最后加密，所以解密时也需要先使用Base64解密，后再使用其他解密