package com.kingdee.eas.custom.integration.base.util;

import java.security.SecureRandom;
import java.util.Base64;

/**
 * API密钥生成工具
 */
public class ApiKeyGenerator {

    private static final SecureRandom RANDOM = new SecureRandom();

    /**
     * 生成appKey，16字节随机数的Base64编码。
     */
    public static String generateAppKey() {
        byte[] bytes = new byte[16];
        RANDOM.nextBytes(bytes);
        return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
    }

    /**
     * 生成appSecret，32字节随机数的Base64编码。
     */
    public static String generateAppSecret() {
        byte[] bytes = new byte[32];
        RANDOM.nextBytes(bytes);
        return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
    }


    public static void main(String[] args) {
        System.out.println("appKey:    " + generateAppKey());
        System.out.println("appSecret: " + generateAppSecret());
    }
}
