Package io.conducive.client.crypt

Source Code of io.conducive.client.crypt.KeysTest

package io.conducive.client.crypt;

import com.googlecode.gwt.crypto.bouncycastle.AsymmetricCipherKeyPair;
import com.googlecode.gwt.crypto.bouncycastle.params.RSAKeyParameters;
import com.googlecode.gwt.crypto.bouncycastle.params.RSAPrivateCrtKeyParameters;
import org.junit.Test;

import static org.junit.Assert.*;


/**
* @author Reuben Firmin
*/
public class KeysTest {

    @Test
    public void testGenerateAndSerialize() throws Exception {
        AsymmetricCipherKeyPair kp1 = RSA.makeKeypairSlow(RSA.Strength.FOUR);

        String test = "this is a test 12345 \n \n !!! 123";
        byte[] encrypted = RSA.encrypt((RSAKeyParameters) kp1.getPublic(), test);

        String decrypted = RSA.decrypt((RSAPrivateCrtKeyParameters) kp1.getPrivate(), encrypted);
        assertEquals(test, decrypted);

        String serialized = RSA.serialize((RSAPrivateCrtKeyParameters) kp1.getPrivate());
        RSAPrivateCrtKeyParameters priv2 = RSA.deserialize(serialized);

        String decrypted2 = RSA.decrypt(priv2, encrypted);
        assertEquals(test, decrypted2);
    }
}
TOP

Related Classes of io.conducive.client.crypt.KeysTest

TOP
Copyright © 2018 www.massapi.com. 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.