BcDSAKeyPairGenerator extends AbstractBcKeyPairGenerator { @Override public AsymmetricKeyPair generate() { return generate(new DSAKeyParametersGenerationParameters()); }  @Override AsymmetricKeyPair generate(); @Override AsymmetricKeyPair generate(KeyGenerationParameters parameters);  }
@Test void generateWithoutArgument() { AsymmetricKeyPair kp1 = generator.generate(); AsymmetricKeyPair kp2 = generator.generate(); assertThat(kp1, not(nullValue())); assertThat(kp2, not(nullValue())); assertThat(kp1.getPrivate(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(kp2.getPrivate(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(kp1.getPublic(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(kp2.getPublic(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp1.getPrivate()).getParameters(), instanceOf(DSAPrivateKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp2.getPrivate()).getParameters(), instanceOf(DSAPrivateKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp1.getPublic()).getParameters(), instanceOf(DSAPublicKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp2.getPublic()).getParameters(), instanceOf(DSAPublicKeyParameters.class)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp1.getPrivate()).getParameters()).getParameters().getP() .bitLength(), equalTo(1024)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp2.getPrivate()).getParameters()).getParameters().getP() .bitLength(), equalTo(1024)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp1.getPublic()).getParameters()).getParameters().getP() .bitLength(), equalTo(1024)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp2.getPublic()).getParameters()).getParameters().getP() .bitLength(), equalTo(1024)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp1.getPrivate()).getParameters()).getParameters().getQ() .bitLength(), equalTo(160)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp2.getPrivate()).getParameters()).getParameters().getQ() .bitLength(), equalTo(160)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp1.getPublic()).getParameters()).getParameters().getQ() .bitLength(), equalTo(160)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp2.getPublic()).getParameters()).getParameters().getQ() .bitLength(), equalTo(160)); }
@Test void generateFIPS186_2() { DSAKeyGenerationParameters params = (DSAKeyGenerationParameters) parameterGenerator.generate(); assertThat(params, not(nullValue())); assertThat(params.getP().bitLength(), equalTo(1024)); assertThat(params.getQ().bitLength(), equalTo(160)); AsymmetricKeyPair kp1 = generator.generate(params); assertThat(kp1, not(nullValue())); assertThat(kp1.getPrivate(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(kp1.getPublic(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp1.getPrivate()).getParameters(), instanceOf(DSAPrivateKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp1.getPublic()).getParameters(), instanceOf(DSAPublicKeyParameters.class)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp1.getPrivate()).getParameters()).getParameters().getP() .bitLength(), equalTo(1024)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp1.getPublic()).getParameters()).getParameters().getP() .bitLength(), equalTo(1024)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp1.getPrivate()).getParameters()).getParameters().getQ() .bitLength(), equalTo(160)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp1.getPublic()).getParameters()).getParameters().getQ() .bitLength(), equalTo(160)); AsymmetricKeyPair kp2 = generator.generate(params); assertThat(kp2, not(nullValue())); assertThat(kp2.getPrivate(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(kp2.getPublic(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp2.getPrivate()).getParameters(), instanceOf(DSAPrivateKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp2.getPublic()).getParameters(), instanceOf(DSAPublicKeyParameters.class)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp2.getPrivate()).getParameters()).getParameters().getP() .bitLength(), equalTo(1024)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp2.getPublic()).getParameters()).getParameters().getP() .bitLength(), equalTo(1024)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp2.getPrivate()).getParameters()).getParameters().getQ() .bitLength(), equalTo(160)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp2.getPublic()).getParameters()).getParameters().getQ() .bitLength(), equalTo(160)); assertThat(kp2, not(equalTo(kp1))); }
@Test void testGenerateFIPS186_3() { DSAKeyGenerationParameters params = (DSAKeyGenerationParameters) parameterGenerator.generate( new DSAKeyParametersGenerationParameters(256, 28, 1) ); assertThat(params, not(nullValue())); assertThat(params.getP().bitLength(), equalTo(2048)); assertThat(params.getQ().bitLength(), equalTo(224)); AsymmetricKeyPair kp = generator.generate(params); assertThat(kp, not(nullValue())); assertThat(kp.getPrivate(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(kp.getPublic(), instanceOf(BcAsymmetricKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp.getPrivate()).getParameters(), instanceOf(DSAPrivateKeyParameters.class)); assertThat(((BcAsymmetricKeyParameters) kp.getPublic()).getParameters(), instanceOf(DSAPublicKeyParameters.class)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp.getPrivate()).getParameters()).getParameters().getP() .bitLength(), equalTo(2048)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp.getPublic()).getParameters()).getParameters().getP() .bitLength(), equalTo(2048)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp.getPrivate()).getParameters()).getParameters().getQ() .bitLength(), equalTo(224)); assertThat( ((DSAKeyParameters) ((BcAsymmetricKeyParameters) kp.getPublic()).getParameters()).getParameters().getQ() .bitLength(), equalTo(224)); }