lebronjamesuit / social-media-platforms

Build an backend app social media, secure my API using Spring Security 6 and Auth0. Deployed AWS.
https://lbconfessionapis-2012569758.eu-west-2.elb.amazonaws.com/swagger-ui/index.html
1 stars 0 forks source link

generate RSA key pair - Private Key and Public key #2

Open lebronjamesuit opened 1 year ago

lebronjamesuit commented 1 year ago

KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(2048); // Set the key size (in bits) KeyPair keyPair = keyPairGenerator.generateKeyPair();

        // Get the public and private keys from the key pair
        PublicKey publicKey = keyPair.getPublic();
        PrivateKey privateKey = keyPair.getPrivate();

        // Print the keys (encoded in Base64)
        System.out.println("Public Key: " + java.util.Base64.getEncoder().encodeToString(publicKey.getEncoded()));
        System.out.println("Private Key: " + java.util.Base64.getEncoder().encodeToString(privateKey.getEncoded()));
lebronjamesuit commented 1 year ago

RSA Key Pair

create rsa key pair

openssl genrsa -out keypair.pem 2048

extract public key

openssl rsa -in keypair.pem -pubout -out public.pem

create private key in PKCS#8 format

openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in keypair.pem -out private.pem