Code example for RSAPrivateKeySpec

0
     */ 
    @TestTargetNew( 
        level = TestLevel.COMPLETE, 
        notes = "", 
        method = "getModulus", 
        args = {} 
    ) 
    public void test_getModulus() throws Exception { 
        KeyFactory gen = KeyFactory.getInstance("RSA");
        final BigInteger n = BigInteger.valueOf(3233);
        final BigInteger d = BigInteger.valueOf(2753);
        final BigInteger e = BigInteger.valueOf(17);
        RSAKey key = null; 
         
        // Case 1: check private key 
        key = (RSAKey) gen.generatePrivate(new RSAPrivateKeySpec(n, d));
        assertEquals("invalid modulus", n, key.getModulus());
         
        // Case 2: check public key 
        key = (RSAKey) gen.generatePublic(new RSAPublicKeySpec(n, e));
        assertEquals("invalid modulus", n, key.getModulus());