package com.gem.media.splash.base.crash;

import android.util.Base64;


public class AesCodeC{

    private final String iv;

    private final String key;

    public AesCodeC(String iv, String key) {
        this.iv = iv;
        this.key = key;
    }

    public String decode(String encContent) throws Throwable {
        return decryptContent(encContent);
    }

    private String decryptContent(String responseContent) throws Exception {
        responseContent = trimEncryptContent(responseContent);
        byte[] decode = Base64.decode(responseContent, Base64.NO_WRAP);
        decode = AesUtils.decryptByte(key, iv, decode);
        return new String(decode, "utf-8");
    }

    private String trimEncryptContent(String responseContent) {
        if (responseContent.startsWith("\"")) {
            responseContent = responseContent.substring(1);
        }
        if (responseContent.endsWith("\"")) {
            responseContent = responseContent.substring(0, responseContent.length() - 1);
        }
        return responseContent;
    }
}
