Code example for RSAPrivateKey

Methods: getModulus

0
		//given 
		KeyPair generatedKeyPair = RSAKeyPairGenerator.generateRSAKeyPair(1024, RSAKeyGenParameterSpec.F4);
		 
		//when 
		RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) generatedKeyPair.getPrivate();
		BigInteger modulus = rsaPrivateKey.getModulus();
		 
		//then 
		Assertions.assertThat(modulus.bitLength()).isEqualTo(1024);
	} 
	 
	@Test 
	public void shouldSignAndVerifyCorrectly() throws Exception { 
		// given 
		KeyPair generatedKeyPair = RSAKeyPairGenerator.generateRSAKeyPair(1024, RSAKeyGenParameterSpec.F4);
 
		// when 
		Signature signer = Signature.getInstance("SHA1withRSA", "BC");
		signer.initSign(generatedKeyPair.getPrivate());
		signer.update("TestSignatureString".getBytes());
		byte[] signature = signer.sign();