package de.ivu.elect.encrypt;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class KeyGenerator {

  private final KeyGeneratorConfig keyGeneratorConfig;

  public KeyGenerator(KeyGeneratorConfig keyGeneratorConfig){
    this.keyGeneratorConfig = keyGeneratorConfig;
  }

  public KeyPair generateKeyPair() throws NoSuchAlgorithmException {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance(keyGeneratorConfig.getAlgorithm());
    SecureRandom random = SecureRandom.getInstanceStrong();
    keyGen.initialize(keyGeneratorConfig.getKeySize(), random);
    return keyGen.generateKeyPair();
  }
}
