Example usage for org.bouncycastle.crypto AsymmetricCipherKeyPair AsymmetricCipherKeyPair

List of usage examples for org.bouncycastle.crypto AsymmetricCipherKeyPair AsymmetricCipherKeyPair

Introduction

In this page you can find the example usage for org.bouncycastle.crypto AsymmetricCipherKeyPair AsymmetricCipherKeyPair.

Prototype

public AsymmetricCipherKeyPair(CipherParameters publicParam, CipherParameters privateParam) 

Source Link

Document

basic constructor.

Usage

From source file:fc.exper.Security.java

License:Open Source License

private static void initSecurity() {
    BigInteger modulus = new BigInteger(
            "114223138481062383818743472854345446729415521820579721478671411120076686448918620302220709845014730631814478188984612465856840519852245805751892337820823145686311359090114506894126920369485682523288840662511969165284005936035859388250282090838456799125935768645086141305672131191153192376610593502582005436827");
    BigInteger pub = new BigInteger("65537");
    BigInteger priv = new BigInteger(
            "70156155961948275567326563815950795233214260644274158546789757111501088844901677266662957312531515817361615431606536850758127492036749476157451855811245452516036408423715290481767027536732741413397901727264890487785997545700283017129062803344411768517700818077537872436050914359831030152123534899150431708577");
    RSAKeyParameters privParam = new RSAKeyParameters(true, modulus, priv);
    RSAKeyParameters pubParam = new RSAKeyParameters(true, modulus, pub);
    keyPair = new AsymmetricCipherKeyPair(pubParam, privParam);
    key = new byte[16];
    random.nextBytes(key);//ww  w .j  a v  a  2 s.c om
}

From source file:org.ethereum.crypto.CryptoTest.java

License:Open Source License

@Test // ECIES_AES128_SHA256 + Ephemeral Key + IV(all zeroes)
public void test15() throws Throwable {

    byte[] privKey = Hex.decode("a4627abc2a3c25315bff732cb22bc128f203912dd2a840f31e66efb27a47d2b1");

    ECKey ecKey = ECKey.fromPrivate(privKey);

    ECPrivateKeyParameters ecPrivKey = new ECPrivateKeyParameters(ecKey.getPrivKey(), ECKey.CURVE);
    ECPublicKeyParameters ecPubKey = new ECPublicKeyParameters(ecKey.getPubKeyPoint(), ECKey.CURVE);

    AsymmetricCipherKeyPair myKey = new AsymmetricCipherKeyPair(ecPubKey, ecPrivKey);

    AESEngine aesEngine = new AESEngine();

    IESEngine iesEngine = new IESEngine(new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()), new BufferedBlockCipher(new SICBlockCipher(aesEngine)));

    byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };

    IESParameters p = new IESWithCipherParameters(d, e, 64, 128);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[16]);

    ECKeyPairGenerator eGen = new ECKeyPairGenerator();
    KeyGenerationParameters gParam = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());

    eGen.init(gParam);//from w w w .j  a v  a2s .c  o  m

    ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());
    ECKeyPairGenerator generator = new ECKeyPairGenerator();
    generator.init(keygenParams);

    EphemeralKeyPairGenerator kGen = new EphemeralKeyPairGenerator(generator, new KeyEncoder() {
        public byte[] getEncoded(AsymmetricKeyParameter keyParameter) {
            return ((ECPublicKeyParameters) keyParameter).getQ().getEncoded();
        }
    });

    ECKeyPairGenerator gen = new ECKeyPairGenerator();
    gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()));

    iesEngine.init(myKey.getPublic(), parametersWithIV, kGen);

    byte[] message = Hex.decode("010101");
    log.info("payload: {}", Hex.toHexString(message));

    byte[] cipher = iesEngine.processBlock(message, 0, message.length);
    log.info("cipher: {}", Hex.toHexString(cipher));

    IESEngine decryptorIES_Engine = new IESEngine(new ECDHBasicAgreement(),
            new KDF2BytesGenerator(new SHA256Digest()), new HMac(new SHA256Digest()),
            new BufferedBlockCipher(new SICBlockCipher(aesEngine)));

    decryptorIES_Engine.init(myKey.getPrivate(), parametersWithIV, new ECIESPublicKeyParser(ECKey.CURVE));

    byte[] orig = decryptorIES_Engine.processBlock(cipher, 0, cipher.length);

    log.info("orig: " + Hex.toHexString(orig));
}

From source file:org.fdroid.enigtext.crypto.KeyPair.java

License:Open Source License

public AsymmetricCipherKeyPair getKeyPair() {
    return new AsymmetricCipherKeyPair(publicKey.getKey(), privateKey);
}

From source file:org.fdroid.enigtext.crypto.KeyUtil.java

License:Open Source License

private static AsymmetricCipherKeyPair cloneKeyPairWithPointCompression(AsymmetricCipherKeyPair keyPair) {
    ECPublicKeyParameters publicKey = (ECPublicKeyParameters) keyPair.getPublic();
    ECPoint q = publicKey.getQ();

    return new AsymmetricCipherKeyPair(
            new ECPublicKeyParameters(new ECPoint.Fp(q.getCurve(), q.getX(), q.getY(), true),
                    publicKey.getParameters()),
            keyPair.getPrivate());/*from w  w w .  jav a 2 s .co  m*/
}