package com.ruoyi.common.config;


import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.RSA;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.security.KeyPair;

@Configuration
@ConfigurationProperties(prefix = "ruoyi.rsa")
@Data
public class RSAProperties {

  /**
   * RSA算法公钥
   */
  private String publicKey="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDgUXdJsNiXcP7PYSQYsqqAXOHW7H3nya+9XbxDnKS3VP6erO9B4nxebmb761W+NaLImhpooCk6uwDinPVggkqKkpAXxbtepU2INW+0bqqIMHAd1hnsqlx8kRQCfCeP+ZHXas1bN0uvue5uPdHZGbaRPnWpgJsHSko5VTEoAwjITwIDAQAB";

  /**
   * RSA算法秘钥
   */
  private String privateKey="MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOBRd0mw2Jdw/s9hJBiyqoBc4dbsfefJr71dvEOcpLdU/p6s70HifF5uZvvrVb41osiaGmigKTq7AOKc9WCCSoqSkBfFu16lTYg1b7RuqogwcB3WGeyqXHyRFAJ8J4/5kddqzVs3S6+57m490dkZtpE+damAmwdKSjlVMSgDCMhPAgMBAAECgYAH+an0WHw2cGVMKatFX4YjkIZF5/izjCWokEymoLzUBycTAe7k2H8UCYZ8lzRufKWVeUBAHXkw5hVGzqOu8zhDukJB7nZwD+bOhrUo1T01kYbh/kNiM97tpqEH8dEdIvxQyA6vznkqsoV8pvjCHrYDuc7YZBF1jSKudRVvfmcTTQJBAP1cjcBD1MheKfbDofscI0AVFLzd7G7hyiQkPIaS704YDC+sCnvL7HCb74b8uVDmpQ7i0PMlHD31xE8l+rbfKYsCQQDip3wMyZ6wRpAcg1x9VHQhN0PWfAJdea/9axSchpA9WZRBdQm6PQ9X+b6pism3ys1mPmb4Wtc5i7kZzq+NZgzNAkEArSms2FOEAs4Y8EcVVoMMtKez3MHw7nfzqG/7zh5u4HkfGxYCtEnT98McGq5wGhMJjPsIxKYAf3iSC2ZxzLsJsQJBAN18w8mPQUaLPgrPB5Pl8rH+2oj/mCQWZTek63hmOw/ouOsaXw4i2xqikIIHgUXcpcmzU1aBFu9CLfkdNApeXkUCQQDFBad1+kTHX5X9ZGSakSsUOcDM1Nqruoj6P8IxUswXc20C6h9nm1kiydzUVK+jR3PbDCM2JdYpz35NJSCixr1t";


  @Setter(AccessLevel.NONE)//不要setter方法
  private RSA rsa;

  @PostConstruct
  public void init() {
    rsa = new RSA(privateKey, publicKey);
  }

  public static void main(String[] args) {
    KeyPair pair = SecureUtil.generateKeyPair("RSA");
    System.out.println(Base64.encode(pair.getPublic().getEncoded()));
    System.out.println();
    System.out.println(Base64.encode(pair.getPrivate().getEncoded()));

  }
}
