import com.ho.common.tools.util.AESEncryptUtil;
import com.ho.common.tools.util.RSAUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author fancl
 * @desc:
 * @date 2022/11/15
 */
@Slf4j
public class EncTest {
    public static void main(String[] args) {
        String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuG6ZABNgLQCI9iVPDuJEb7xb5zR9UGKyKXshLuJFZxyNtaEzfpjSMqsshUYA1QpwUvkmZE0lcRE4F4QtZO9rDnH2PoW1FWRbjgg0+MKWOmZr9hSPKM/BIE+knTtTaj4/0TK7QwDd9q/QAIduC1hIyxIIkxfWx0gFuTnxui0waCwIDAQAB";
        String privKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAK4bpkAE2AtAIj2JU8O4kRvvFvnNH1QYrIpeyEu4kVnHI21oTN+mNIyqyyFRgDVCnBS+SZkTSVxETgXhC1k72sOcfY+hbUVZFuOCDT4wpY6Zmv2FI8oz8EgT6SdO1NqPj/RMrtDAN32r9AAh24LWEjLEgiTF9bHSAW5OfG6LTBoLAgMBAAECgYA614NfXYO6galQzMmvewAnxa0pLYbqABDIDvJ4jN8qzV+OyVI5v81AwTQ3hXjkBygC5rCu+FKxyS/pUr5oIQ90vbKvy+kozg9l0qWHfa8XrfC+E36CVuDrZYdZzl0C6J6BoNB9osJJ6HCnMA7kWLRRwU5VJBsK8CmgcJlfHNH60QJBAPz4rZgqgor69SonHG4xjRz+u4QkXIP8I+lorBSFEuUF03u22Kcxz7mcOq63m8K+oc22ql0g8QNrq6YPrEgpAPMCQQCwMUQcdZLWJrRbHp1ZA3jbt4vYg7xb1LklAM6Qmz1R9xVY0itDMtFRSTlVnrbTPZ+rldrkLUOzLJwKLHniIQiJAkEAmfeBMKwu6Af2T8GePDNMf+lKmBLJfEtqUBW1JogYB+yT2yhelORsWbwMu2plExKTyHD1H9l812ghAOFpKkJKoQJBAJ7lz2dbIXHAtib3FTCR0Q1WGujI5bZrwg19DM2dM1AYZUgVQq73xY5pWyu8V2VqzfUQ0Le3mracJJ2IPuOQpwECQF/b7Tv3auIHRaO9AD7xWIOCMYGlKhqeheMZb/mDRHedsdRvigiojDaaFbtnkvXlRbWlkOu5P5GNDpv7EuPbUs8=";
        //AES加解密
        //String aesKey = AESEncryptUtil.generateKeyAndIv();
        //String iv = AESEncryptUtil.generateKeyAndIv();
        String aesKey = "1111111111111111";
        String iv =     "2222222222222222";
        log.info("aesKey: {} ,iv:{}" ,aesKey ,iv);
        //先加密
        String plainText = "666666";
        log.info("原始内容: {}" ,plainText);
        String encryptData = AESEncryptUtil.encrypt(plainText, aesKey, iv);
        log.info("密码加密后: {}" ,encryptData);
        //对密钥加密
        String aesKeyEnc = RSAUtil.encode(aesKey, publicKey);
        String ivEnc = RSAUtil.encode(iv, publicKey);
        log.info("aesKeyEnc: {}" ,aesKeyEnc );
        log.info("ivEnc:{}", ivEnc );
        //解密
        //对密钥解密
        String aesKeyPlain = RSAUtil.decode(aesKeyEnc, privKey);
        String ivPlain = RSAUtil.decode(ivEnc, privKey);
        log.info("解密后: aesKeyPlain:{}" ,aesKeyPlain);
        log.info("解密后: ivPlain:{}" ,ivPlain);
        String srcPlain = AESEncryptUtil.decrypt(encryptData, aesKeyPlain ,ivPlain);
        log.info("解密后密码: {}" ,srcPlain);

    }

 }
