Package org.jboss.aerogear.crypto.keys

Examples of org.jboss.aerogear.crypto.keys.KeyPair


            throw new RuntimeException("Error: ", e);
        }
    }

    public SigningKey() {
        this(new KeyPair(ECDSA_ALGORITHM_NAME, DEFAULT_CURVE_NAME));
    }
View Full Code Here


    }

    @Test
    public void testAcceptPublicPrivateKeys() throws Exception {
        try {
            KeyPair keyPair = new KeyPair();
            new CryptoBox(keyPair.getPrivateKey(), keyPair.getPublicKey());
        } catch (Exception e) {
            e.printStackTrace();
            fail("Box should accept key pairs");
        }
    }
View Full Code Here

    }

    @Test
    public void testAcceptKeyPair() throws Exception {
        try {
            KeyPair keyPair = new KeyPair();
            new CryptoBox(keyPair);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Box should accept key pairs");
        }
View Full Code Here

    }


    @Test(expected = RuntimeException.class)
    public void testNullPublicKey() throws Exception {
        KeyPair keyPair = new KeyPair();
        new CryptoBox(keyPair.getPrivateKey(), null);
        fail("Should raise an exception");
    }
View Full Code Here

        fail("Should raise an exception");
    }

    @Test(expected = RuntimeException.class)
    public void testNullSecretKey() throws Exception {
        KeyPair keyPair = new KeyPair();
        new CryptoBox(null, keyPair.getPublicKey());
        fail("Should raise an exception");
    }
View Full Code Here

        fail("Should raise an exception");
    }

    @Test
    public void testAsymmetricDecryptRawBytes() throws Exception {
        KeyPair keyPair = new KeyPair();
        KeyPair keyPairPandora = new KeyPair();

        CryptoBox cryptoBox = new CryptoBox(keyPair.getPrivateKey(), keyPairPandora.getPublicKey());
        byte[] IV = HEX.decode(BOX_NONCE);
        byte[] expectedMessage = HEX.decode(BOX_MESSAGE);
        byte[] ciphertext = cryptoBox.encrypt(IV, expectedMessage);

        CryptoBox pandora = new CryptoBox(keyPairPandora.getPrivateKey(), keyPair.getPublicKey());
        byte[] message = pandora.decrypt(IV, ciphertext);
        assertTrue("failed to decrypt ciphertext", Arrays.equals(message, expectedMessage));
    }
View Full Code Here

        byte[] bobPrivateKey = HEX.decode(BOB_PRIVATE_KEY);
        byte[] bobPublicKey = HEX.decode(BOB_PUBLIC_KEY);
        byte[] alicePrivateKey = HEX.decode(ALICE_PRIVATE_KEY);
        byte[] alicePublicKey = HEX.decode(ALICE_PUBLIC_KEY);

        KeyPair cryptoBoxKeyPair = new KeyPair(bobPrivateKey, alicePublicKey);

        CryptoBox cryptoBox = new CryptoBox(cryptoBoxKeyPair.getPrivateKey(), cryptoBoxKeyPair.getPublicKey());
        byte[] IV = HEX.decode(BOX_NONCE);
        byte[] expectedMessage = HEX.decode(BOX_MESSAGE);
        byte[] ciphertext = cryptoBox.encrypt(IV, expectedMessage);

        KeyPair pandoraBoxKeyPair = new KeyPair(alicePrivateKey, bobPublicKey);

        CryptoBox pandora = new CryptoBox(pandoraBoxKeyPair.getPrivateKey(), pandoraBoxKeyPair.getPublicKey());
        byte[] message = pandora.decrypt(IV, ciphertext);
        assertTrue("failed to decrypt ciphertext", Arrays.equals(message, expectedMessage));
    }
View Full Code Here

    }

    @Test
    public void testAsymmetricDecryptionWithRawKeysAndEncoderProvided() throws Exception {

        KeyPair cryptoBoxKeyPair = new KeyPair(BOB_PRIVATE_KEY, ALICE_PUBLIC_KEY, HEX);

        CryptoBox cryptoBox = new CryptoBox(cryptoBoxKeyPair.getPrivateKey(), cryptoBoxKeyPair.getPublicKey());
        byte[] IV = HEX.decode(BOX_NONCE);
        byte[] expectedMessage = HEX.decode(BOX_MESSAGE);
        byte[] ciphertext = cryptoBox.encrypt(IV, expectedMessage);

        KeyPair pandoraBoxKeyPair = new KeyPair(ALICE_PRIVATE_KEY, BOB_PUBLIC_KEY, HEX);

        CryptoBox pandora = new CryptoBox(pandoraBoxKeyPair.getPrivateKey(), pandoraBoxKeyPair.getPublicKey());
        byte[] message = pandora.decrypt(IV, ciphertext);
        assertTrue("failed to decrypt ciphertext", Arrays.equals(message, expectedMessage));
    }
View Full Code Here

        assertTrue("failed to decrypt ciphertext", Arrays.equals(message, expectedMessage));
    }

    @Test(expected = RuntimeException.class)
    public void testAsymmetricDecryptCorruptedCipherText() throws Exception {
        KeyPair keyPair = new KeyPair();
        CryptoBox box = new CryptoBox(keyPair.getPrivateKey(), keyPair.getPublicKey());
        byte[] nonce = HEX.decode(BOX_NONCE);
        byte[] message = HEX.decode(BOX_MESSAGE);
        byte[] ciphertext = box.encrypt(nonce, message);
        ciphertext[23] = ' ';

        KeyPair keyPairPandora = new KeyPair();
        CryptoBox pandora = new CryptoBox(keyPairPandora.getPrivateKey(), keyPairPandora.getPublicKey());
        pandora.decrypt(nonce, ciphertext);
        fail("Should raise an exception");
    }
View Full Code Here

TOP

Related Classes of org.jboss.aerogear.crypto.keys.KeyPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.