Exemple #1
0
        private IIesEngine MakeIesEngine(bool isEncrypt, PublicKey publicKey, PrivateKey privateKey, byte[] iv)
        {
            AesEngine aesFastEngine = new AesEngine();

            EthereumIesEngine iesEngine = new EthereumIesEngine(
                new HMac(new Sha256Digest()),
                new Sha256Digest(),
                new BufferedBlockCipher(new SicBlockCipher(aesFastEngine)));

            IesParameters    iesParameters    = new IesWithCipherParameters(new byte[] { }, new byte[] { }, KeySize, KeySize);
            ParametersWithIV parametersWithIV = new ParametersWithIV(iesParameters, iv);

            byte[] secret = Proxy.EcdhSerialized(publicKey.Bytes, privateKey.KeyBytes);
            iesEngine.Init(isEncrypt, _optimizedKdf.Derive(secret), parametersWithIV);
            return(iesEngine);
        }
Exemple #2
0
        private static EthereumIesEngine MakeIesEngine(bool isEncrypt, ECPublicKeyParameters pub, ECPrivateKeyParameters prv, byte[] iv)
        {
            AesEngine aesFastEngine = new AesEngine();

            EthereumIesEngine iesEngine = new EthereumIesEngine(
                new ECDHBasicAgreement(),
                new ConcatKdfBytesGenerator(new Sha256Digest()),
                new HMac(new Sha256Digest()),
                new Sha256Digest(),
                new BufferedBlockCipher(new SicBlockCipher(aesFastEngine)));

            IesParameters    iseParameters    = new IesWithCipherParameters(new byte[] { }, new byte[] { }, KeySize, KeySize);
            ParametersWithIV parametersWithIV = new ParametersWithIV(iseParameters, iv);

            iesEngine.Init(isEncrypt, prv, pub, parametersWithIV);
            return(iesEngine);
        }
Exemple #3
0
        private byte[] Decrypt(PublicKey ephemeralPublicKey, PrivateKey privateKey, byte[] iv, byte[] ciphertextBody, byte[] macData)
        {
            AesEngine aesFastEngine = new AesEngine();

            EthereumIesEngine iesEngine = new EthereumIesEngine(
                new ECDHBasicAgreement(),
                new ConcatKdfBytesGenerator(new Sha256Digest()),
                new HMac(new Sha256Digest()),
                new Sha256Digest(),
                new BufferedBlockCipher(new SicBlockCipher(aesFastEngine)));

            IesParameters    iesParameters    = new IesWithCipherParameters(new byte[] { }, new byte[] { }, KeySize, KeySize);
            ParametersWithIV parametersWithIV = new ParametersWithIV(iesParameters, iv);

            ECPrivateKeyParameters privateKeyParameters = BouncyCrypto.WrapPrivateKey(privateKey);
            ECPublicKeyParameters  publicKeyParameters  = BouncyCrypto.WrapPublicKey(ephemeralPublicKey);

            iesEngine.Init(false, privateKeyParameters, publicKeyParameters, parametersWithIV);

            return(iesEngine.ProcessBlock(ciphertextBody, 0, ciphertextBody.Length, macData));
        }