package com.weaver.seconddev.chapanda.kaixinyi.util;

//import com.lsy.baselib.crypto.util.Base64;
//import com.lsy.baselib.crypto.util.CryptUtil;
import org.springframework.stereotype.Component;
//import javax.crypto.Cipher;
//import java.io.ByteArrayOutputStream;
//import java.security.Key;
//import java.security.PublicKey;
//import java.security.cert.X509Certificate;
//import java.security.interfaces.RSAKey;


@Component
public class EncryptionUtil {

//    private String encryptBusiness(String business) throws Exception {
//        String encryptKey = AESUtil.getRandomAESKey();
//        byte[] encryptBusinessDataByte = AESUtil.encrypt(business, encryptKey);
//
//        String encryptBusiness = new String(
//                Base64.encode(encryptBusinessDataByte), "UTF-8");
//
//        String publicKey = "MIIDQTCCAimgAwIBAgIBMDANBgkqhkiG9w0BAQUFADA6MQswCQYDVQQGEwJDTjENMAsGA1UECwwEQ05DQjEcMBoGA1UEAwwTYjJjLmJhbmsuZWNpdGljLmNvbTAgFw0xODEwMjIwMjU0MjZaGA8yMTE4MDkyODAyNTQyNlowOjELMAkGA1UEBhMCQ04xDTALBgNVBAsMBENOQ0IxHDAaBgNVBAMME2IyYy5iYW5rLmVjaXRpYy5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCJe5k8J5oxkRbfrNHHbN8MEce9lkV/HWrKtpEtknRICpyT24Rx3xiCkyFfC2Zn0sYofJAcAvKElDupIIuYJHMvwWgakYHVHAbsp8XfGDToDeZdabCPSaV/tC+pbcZjnF+Zdlmy/TL9Yzxe/lSqhAnjk2wIeBQUy27CpcOKO7GXMVFE9TgogqDND+hYYzyaj+8gh73DRu2xSAq+ZTvJuW+bPvuALEOK/Ex8MO9u0oV1nn3OwkPkE/98jSs8BWBRDDGuh9OaZrUoNsF7II/e10Ad93lPf7UTEAiosO7ZiyJ+MBGy+cbkCwjpe5OOrkFr+9GNI6pjcDYul2KgI6XXdX0bAgMBAAGjUDBOMB0GA1UdDgQWBBTFTb+SBCIKxAdjuaOlferd/wKWYTAfBgNVHSMEGDAWgBTFTb+SBCIKxAdjuaOlferd/wKWYTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQA4zYjdRonussCKJGAK+KKI1Ov8ptG9lxuUEjDFCYGG0hgyDfUxuNAIWI3GaDIxfreR/YMXPEOzEl4yORzFEu/ekh5gQvNT674x29BaA1iOKW1w5OJ7N1msJ76J66V4o1FQuFxZFO3U5nIx10eMe1VUezBIRrVO0YXMnCwA4Ckc9m1+5vEWhB78oLLSLgNhUcIwDyXyyb48TjeUO9TGCDECaadLLPsKSEiQ/fp5Nbo2VFrrx3IUMBJDxu6LiXAEZwQ8/cc8O//sT7t5ezu4joLNKGU8Sl6MSW5k2cee76g52MaA0Zt1x3G2viAMtkj5w1hJs8rsMA7+aty6tnbELWZe";
//        byte[] base64EncodedSenderCert = publicKey.getBytes("UTF-8");
//
//        X509Certificate signerCertificate = CryptUtil
//                .generateX509Certificate(com.lsy.baselib.crypto.util.Base64
//                        .decode(base64EncodedSenderCert));
//        PublicKey signpublicKey = signerCertificate.getPublicKey();
//
//        byte[] encryptKeyByte = encrypt((RSAKey) signpublicKey,
//                encryptKey.getBytes("UTF-8"));
//        String encryptKeyString = new String(Base64.encode(encryptKeyByte),
//                "UTF-8");
//
//        encryptBusiness = encryptBusiness + "@@" + encryptKeyString;
//
//        return encryptBusiness;
//    }
//
//    private byte[] encrypt(RSAKey key, byte[] data) {
//        try {
//            Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding", "BC");
//            cipher.init(1, (Key) key);
//            int step = key.getModulus().bitLength() / 8;
//            int n = data.length / step;
//            if (n > 0) {
//                ByteArrayOutputStream baos = new ByteArrayOutputStream();
//                for (int i = 0; i < n; i++) {
//                    baos.write(cipher.doFinal(data, i * step, step));
//                }
//                if ((n = data.length % step) != 0) {
//                    baos.write(cipher.doFinal(data, data.length - n, n));
//                }
//                return baos.toByteArray();
//            }
//            return cipher.doFinal(data);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

}
