package io.common.utils;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class KeyUtil {
    public static KeyPair generateKeyPair() throws NoSuchAlgorithmException {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(2048); // 2048位安全性高
        return keyGen.generateKeyPair();
    }

    public static String encodeKeyToString(byte[] keyBytes) {
        return Base64.getEncoder().encodeToString(keyBytes);
    }
}
