package cn.hztech.sdk;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.*;
import java.util.Base64;

/**
 * 密钥生成工具
 */
public class KeyGeneratorUtil {

    public static void main(String[] args) throws Exception {
        Security.addProvider(new BouncyCastleProvider());

        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC", "BC");
        keyGen.initialize(256);

        // 生成子应用密钥对
        System.out.println("========== 子应用密钥对 ==========");
//        KeyPair subAppKeyPair = keyGen.generateKeyPair();
//        String subAppPrivateKey = Base64.getEncoder().encodeToString(subAppKeyPair.getPrivate().getEncoded());
        String subAppPrivateKey = "MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgXmfOgQqOM8g1l80mxioSOQQW4EnxszaSlXRAKd+SQ++gCgYIKoZIzj0DAQehRANCAATYw2RaAi1MJAI18xUzKUvdQV2fqUotQeCIK4D7170Mrq4pei/rGQ1sJAgSX2vq1x3lOT78zZx1Iaus+pHPgMcb";
//        String subAppPublicKey = Base64.getEncoder().encodeToString(subAppKeyPair.getPublic().getEncoded());
        String subAppPublicKey = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2MNkWgItTCQCNfMVMylL3UFdn6lKLUHgiCuA+9e9DK6uKXov6xkNbCQIEl9r6tcd5Tk+/M2cdSGrrPqRz4DHGw==";
        System.out.println("SUB_APP_PRIVATE_KEY=" + subAppPrivateKey);
        System.out.println("SUB_APP_PUBLIC_KEY=" + subAppPublicKey);

        // 生成平台密钥对
        System.out.println("\n========== 平台密钥对 ==========");
//        KeyPair platformKeyPair = keyGen.generateKeyPair();
//        String platformPrivateKey = Base64.getEncoder().encodeToString(platformKeyPair.getPrivate().getEncoded());
        String platformPrivateKey = "MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQg3ReJcb0WMzNh1oY4v445xk93md5ay69/hgCltP5k4JegCgYIKoZIzj0DAQehRANCAASx33umB6j8dp92QgeRfikMKUPrDB3OiGLpZ6yC4Wi5kdTH4QzH72TIQedaUFXZWr4mmp+smYlSswzGKnvc179Y";
//        String platformPublicKey = Base64.getEncoder().encodeToString(platformKeyPair.getPublic().getEncoded());
        String platformPublicKey = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEsd97pgeo/HafdkIHkX4pDClD6wwdzohi6WesguFouZHUx+EMx+9kyEHnWlBV2Vq+JpqfrJmJUrMMxip73Ne/WA==";
        System.out.println("PLATFORM_PRIVATE_KEY=" + platformPrivateKey);
        System.out.println("PLATFORM_PUBLIC_KEY=" + platformPublicKey);

        System.out.println("\n========== 配置说明 ==========");
        System.out.println("SDK客户端需要:");
        System.out.println("  private-key: " + subAppPrivateKey.substring(0, 50) + "...");
        System.out.println("  platform-public-key: " + platformPublicKey.substring(0, 50) + "...");
        System.out.println("\n模拟服务器需要:");
        System.out.println("  platform-private-key: " + platformPrivateKey.substring(0, 50) + "...");
        System.out.println("  sub-app-public-key: " + subAppPublicKey.substring(0, 50) + "...");
    }
}
