// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.athenz.instanceproviderservice;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * @author bjorncs
 */
public class AutoGeneratedKeyProvider implements KeyProvider {

    private final KeyPair keyPair;

    public AutoGeneratedKeyProvider() {
        try {
            KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");
            rsa.initialize(2048);
            keyPair = rsa.genKeyPair();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public PrivateKey getPrivateKey(int version) {
        return keyPair.getPrivate();
    }

    @Override
    public PublicKey getPublicKey(int version) {
        return keyPair.getPublic();
    }

    public KeyPair getKeyPair() {
        return keyPair;
    }
}

@@ -176,16 +176,93 @@
 rvice;%0A%0A
+import com.yahoo.security.KeyAlgorithm;%0Aimport com.yahoo.security.KeyUtils;%0A%0A
 import j
@@ -614,259 +614,67 @@
     
-try %7B%0A            KeyPairGenerator rsa = KeyPairGenerator.getInstance(%22RSA%22);%0A            rsa.initialize(2048);%0A            keyPair = rsa.genKeyPair();%0A        %7D catch (NoSuchAlgorithmException e) %7B%0A            throw new RuntimeException(e);%0A        %7D
+keyPair = KeyUtils.generateKeypair(KeyAlgorithm.RSA, 2048);
 %0A   

Use KeyUtils