Examples of AsymmetricCipherKeyPair


Examples of com.googlecode.gwt.crypto.bouncycastle.AsymmetricCipherKeyPair

*/
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);
    }
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

            if (!initialised)
            {
                throw new IllegalStateException("EC Key Pair Generator not initialised");
            }

            AsymmetricCipherKeyPair     pair = engine.generateKeyPair();
            ECPublicKeyParameters       pub = (ECPublicKeyParameters)pair.getPublic();
            ECPrivateKeyParameters      priv = (ECPrivateKeyParameters)pair.getPrivate();

            return new KeyPair(new JCEECPublicKey(algorithm, pub, ecParams),
                               new JCEECPrivateKey(algorithm, priv, ecParams));
        }
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

        //
        // calculate the public key.
        //
        y = g.modPow(x, p);

        return new AsymmetricCipherKeyPair(
                new ElGamalPublicKeyParameters(y, elParams),
                new ElGamalPrivateKeyParameters(x, elParams));
    }
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

        //
        // calculate the public key.
        //
        y = g.modPow(x, p);

        return new AsymmetricCipherKeyPair(
                new DHPublicKeyParameters(y, dhParams),
                new DHPrivateKeyParameters(x, dhParams));
    }
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

        //
        // calculate the public key.
        //
        y = g.modPow(x, p);

        return new AsymmetricCipherKeyPair(
                new DHPublicKeyParameters(y, dhParams),
                new DHPrivateKeyParameters(x, dhParams));
    }
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

    }
    while (d.equals(ZERO|| (d.compareTo(n) >= 0));

    ECPoint Q = params.getG().multiply(d);

    return new AsymmetricCipherKeyPair(
            new ECPublicKeyParameters(Q, params),
      new ECPrivateKeyParameters(d, params));
  }
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

        dP = d.remainder(pSub1);
        dQ = d.remainder(qSub1);
        qInv = q.modInverse(p);

        return new AsymmetricCipherKeyPair(
                new RSAKeyParameters(false, n, e),
                new RSAPrivateCrtKeyParameters(n, e, d, p, q, dP, dQ, qInv));
    }
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

             * a suitable curve.
             */
            throw new TlsFatalAlert(AlertDescription.internal_error);
        }

        AsymmetricCipherKeyPair kp = TlsECCUtils.generateECKeyPair(context.getSecureRandom(), curve_params);
        this.ecAgreeServerPrivateKey = (ECPrivateKeyParameters)kp.getPrivate();

        byte[] publicBytes = TlsECCUtils.serializeECPublicKey(clientECPointFormats,
            (ECPublicKeyParameters)kp.getPublic());

        ByteArrayOutputStream buf = new ByteArrayOutputStream();

        if (namedCurve < 0)
        {
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

        if (!initialised)
        {
            throw new IllegalStateException("EC Key Pair Generator not initialised");
        }

        AsymmetricCipherKeyPair pair = engine.generateKeyPair();
        ECPublicKeyParameters pub = (ECPublicKeyParameters)pair.getPublic();
        ECPrivateKeyParameters priv = (ECPrivateKeyParameters)pair.getPrivate();

        if (ecParams instanceof ECParameterSpec)
        {
            ECParameterSpec p = (ECParameterSpec)ecParams;
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricCipherKeyPair

        engine.init(param);
    }

    public KeyPair generateKeyPair()
    {
        AsymmetricCipherKeyPair pair = engine.generateKeyPair();
        RSAKeyParameters pub = (RSAKeyParameters)pair.getPublic();
        RSAPrivateCrtKeyParameters priv = (RSAPrivateCrtKeyParameters)pair.getPrivate();

        return new KeyPair(new BCRSAPublicKey(pub),
            new BCRSAPrivateCrtKey(priv));
    }
View Full Code Here
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.