Example usage for org.bouncycastle.crypto.engines EthereumIESEngine init

List of usage examples for org.bouncycastle.crypto.engines EthereumIESEngine init

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.engines EthereumIESEngine init.

Prototype

public void init(AsymmetricKeyParameter privateKey, CipherParameters params, KeyParser publicKeyParser) 

Source Link

Document

Initialise the encryptor.

Usage

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

License:Open Source License

/**
 *  Encryption equivalent to the Crypto++ default ECIES<ECP> settings:
 *
 *  DL_KeyAgreementAlgorithm:        DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> >
 *  DL_KeyDerivationAlgorithm:       DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> >
 *  DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0>
 *  DL_PrivateKey:                   DL_Key<ECPPoint>
 *  DL_PrivateKey_EC<class ECP>// w ww.  jav  a 2s  .  c  o  m
 *
 *  Used for Whisper V3
 */
public static byte[] decryptSimple(BigInteger privKey, byte[] cipher)
        throws IOException, InvalidCipherTextException {
    EthereumIESEngine iesEngine = new EthereumIESEngine(new ECDHBasicAgreement(),
            new MGF1BytesGeneratorExt(new SHA1Digest(), 1), new HMac(new SHA1Digest()), new SHA1Digest(), null);

    IESParameters p = new IESParameters(null, null, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]);

    iesEngine.setHashMacKey(false);

    iesEngine.init(new ECPrivateKeyParameters(privKey, CURVE), parametersWithIV,
            new ECIESPublicKeyParser(ECKey.CURVE));

    return iesEngine.processBlock(cipher, 0, cipher.length);
}