|
49 | 49 | import java.security.spec.ECGenParameterSpec; |
50 | 50 | import java.security.spec.X509EncodedKeySpec; |
51 | 51 | import java.security.spec.PKCS8EncodedKeySpec; |
| 52 | +import java.security.interfaces.RSAPrivateKey; |
| 53 | +import java.security.interfaces.RSAPublicKey; |
52 | 54 |
|
53 | 55 | import com.wolfssl.wolfcrypt.Rsa; |
54 | 56 | import com.wolfssl.wolfcrypt.Ecc; |
@@ -556,6 +558,40 @@ public void testKeyPairGeneratorDhMultipleKeyGen() |
556 | 558 | assertNotNull(kp2); |
557 | 559 | } |
558 | 560 |
|
| 561 | + @Test |
| 562 | + public void testKeyPairGeneratorRsaDefaultKeySize() |
| 563 | + throws NoSuchProviderException, NoSuchAlgorithmException { |
| 564 | + |
| 565 | + /* Test that RSA KeyPairGenerator works with default parameters |
| 566 | + * without explicit initialization */ |
| 567 | + KeyPairGenerator kpg = |
| 568 | + KeyPairGenerator.getInstance("RSA", "wolfJCE"); |
| 569 | + |
| 570 | + /* Generate key pair without calling initialize() first */ |
| 571 | + KeyPair kp = kpg.generateKeyPair(); |
| 572 | + assertNotNull(kp); |
| 573 | + assertNotNull(kp.getPublic()); |
| 574 | + assertNotNull(kp.getPrivate()); |
| 575 | + |
| 576 | + /* Verify the generated key is RSA and has expected default size */ |
| 577 | + assertTrue(kp.getPublic() instanceof RSAPublicKey); |
| 578 | + assertTrue(kp.getPrivate() instanceof RSAPrivateKey); |
| 579 | + |
| 580 | + RSAPublicKey pubKey = (RSAPublicKey) kp.getPublic(); |
| 581 | + RSAPrivateKey privKey = (RSAPrivateKey) kp.getPrivate(); |
| 582 | + |
| 583 | + /* Default key size should be 2048 bits */ |
| 584 | + assertEquals("Default RSA key size should be 2048 bits", |
| 585 | + 2048, pubKey.getModulus().bitLength()); |
| 586 | + assertEquals("Private key modulus should match public key", |
| 587 | + pubKey.getModulus(), privKey.getModulus()); |
| 588 | + |
| 589 | + /* Verify the default public exponent */ |
| 590 | + assertEquals("Default RSA public exponent should match wolfSSL default", |
| 591 | + BigInteger.valueOf(Rsa.getDefaultRsaExponent()), |
| 592 | + pubKey.getPublicExponent()); |
| 593 | + } |
| 594 | + |
559 | 595 | @Test |
560 | 596 | public void testKeyPairGeneratorRsassaPssKeyGeneration() |
561 | 597 | throws NoSuchProviderException, NoSuchAlgorithmException, |
|
0 commit comments