package com.tutego.ch_09.security;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.nimbusds.jose.jwk.RSAKey;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.UUID;
@Configuration
public class RSAConfiguration {
@Bean
public RSAKey rsaKey() throws NoSuchAlgorithmException {
var generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(2048);
var keyPair = generator.generateKeyPair();
return new RSAKey.Builder((RSAPublicKey) keyPair.getPublic())
.privateKey((RSAPrivateKey) keyPair.getPrivate())
.keyID(UUID.randomUUID().toString())
.build();
}
}