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);
}
}