Add method that returns a standard keypair

feature/mock
Richard Körber 2019-11-03 23:49:54 +01:00
parent b9b7bda342
commit 3ce5b8bd4f
No known key found for this signature in database
GPG Key ID: AAB9FD19C78AA3E0
2 changed files with 26 additions and 0 deletions

View File

@ -46,6 +46,19 @@ public class KeyPairUtils {
// utility class without constructor
}
/**
* Creates a new standard {@link KeyPair}.
* <p>
* This method can be used if no specific key type is required. It returns a
* "secp384r1" ECDSA key pair.
*
* @return Generated {@link KeyPair}
* @since 2.8
*/
public static KeyPair createKeyPair() {
return createECKeyPair("secp384r1");
}
/**
* Creates a new RSA {@link KeyPair}.
*

View File

@ -42,6 +42,19 @@ public class KeyPairUtilsTest {
Security.addProvider(new BouncyCastleProvider());
}
/**
* Test that standard keypair generates a secure key pair.
*/
@Test
public void testCreateStandardKeyPair() {
KeyPair pair = KeyPairUtils.createKeyPair();
assertThat(pair, is(notNullValue()));
assertThat(pair.getPublic(), is(instanceOf(ECPublicKey.class)));
ECPublicKey pk = (ECPublicKey) pair.getPublic();
assertThat(pk.getAlgorithm(), is("ECDSA"));
assertThat(pk.getParams().getCurve().getField().getFieldSize(), is(384));
}
/**
* Test that RSA keypairs of the correct size are generated.
*/