Leem.fin
Leem.fin

Reputation: 42602

Generate private key & public key in my case

I need to create a function which could always generate the same private key/public key every time it is called.

Here is my function code I created:

public void generateTheUniqueKeys() {
    KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
    keyGenerator.initialize(512);
    KeyPair keyPair = keyGenerator.generateKeyPair();
    // I need every time when this function is called, it generate the same keys as that generated from previous call
    PrivateKey privateKey = keyPair.getPrivate();
    PublicKey pubKey = keyPair.getPublic();
}

How can I make my function to always generated the same key pair?

Upvotes: 0

Views: 1632

Answers (1)

DiogoSantana
DiogoSantana

Reputation: 2434

You can generate the keys once and store in a file so the function always retrieve the same key pair from the file.

Upvotes: 1

Related Questions