org.bouncycastle.crypto.params.KDFParameters Java Examples
The following examples show how to use
org.bouncycastle.crypto.params.KDFParameters.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RLPxConnectionFactory.java From incubator-tuweni with Apache License 2.0 | 5 votes |
private static EthereumIESEncryptionEngine forDecryption( SecretKey privateKey, PublicKey ephemeralPublicKey, Bytes iv, Bytes commonMac) { CipherParameters pubParam = new ECPublicKeyParameters(ephemeralPublicKey.asEcPoint(), CURVE); CipherParameters privParam = new ECPrivateKeyParameters(privateKey.bytes().toUnsignedBigInteger(), CURVE); BasicAgreement agreement = new ECDHBasicAgreement(); agreement.init(privParam); byte[] agreementValue = BigIntegers.asUnsignedByteArray(agreement.getFieldSize(), agreement.calculateAgreement(pubParam)); IESWithCipherParameters iesWithCipherParameters = new IESWithCipherParameters(new byte[0], new byte[0], 128, 128); EthereumIESEncryptionEngine.ECIESHandshakeKDFFunction kdf = new EthereumIESEncryptionEngine.ECIESHandshakeKDFFunction(1, new SHA256Digest()); kdf.init(new KDFParameters(agreementValue, iesWithCipherParameters.getDerivationV())); EthereumIESEncryptionEngine engine = new EthereumIESEncryptionEngine( agreement, kdf, new HMac(new SHA256Digest()), commonMac.toArrayUnsafe(), new BufferedBlockCipher(new SICBlockCipher(new AESEngine()))); ParametersWithIV cipherParameters = new ParametersWithIV(iesWithCipherParameters, iv.toArrayUnsafe()); engine.init(false, privParam, pubParam, cipherParameters); return engine; }
Example #2
Source File: ECIESEncryptionEngine.java From besu with Apache License 2.0 | 5 votes |
private ECIESEncryptionEngine( final Bytes agreedSecret, final SECP256K1.PublicKey ephPubKey, final byte[] iv) { this.ephPubKey = ephPubKey; this.iv = iv; // Initialise the KDF. this.kdf.init(new KDFParameters(agreedSecret.toArrayUnsafe(), PARAM.getDerivationV())); }
Example #3
Source File: ECIESEncryptionEngine.java From besu with Apache License 2.0 | 5 votes |
@Override public void init(final DerivationParameters param) { checkArgument(param instanceof KDFParameters, "unexpected expected KDF params type"); final KDFParameters p = (KDFParameters) param; shared = p.getSharedSecret(); iv = p.getIV(); }
Example #4
Source File: RLPxConnectionFactory.java From cava with Apache License 2.0 | 5 votes |
private static EthereumIESEncryptionEngine forEncryption( PublicKey pubKey, Bytes iv, Bytes commonMac, KeyPair ephemeralKeyPair) { CipherParameters pubParam = new ECPublicKeyParameters(pubKey.asEcPoint(), CURVE); CipherParameters privParam = new ECPrivateKeyParameters(ephemeralKeyPair.secretKey().bytes().toUnsignedBigInteger(), CURVE); BasicAgreement agree = new ECDHBasicAgreement(); agree.init(privParam); BigInteger z = agree.calculateAgreement(pubParam); byte[] zbytes = BigIntegers.asUnsignedByteArray(agree.getFieldSize(), z); IESWithCipherParameters iesWithCipherParameters = new IESWithCipherParameters(new byte[0], new byte[0], 128, 128); // Initialise the KDF. EthereumIESEncryptionEngine.ECIESHandshakeKDFFunction kdf = new EthereumIESEncryptionEngine.ECIESHandshakeKDFFunction(1, new SHA256Digest()); kdf.init(new KDFParameters(zbytes, iesWithCipherParameters.getDerivationV())); EthereumIESEncryptionEngine engine = new EthereumIESEncryptionEngine( agree, kdf, new HMac(new SHA256Digest()), commonMac.toArrayUnsafe(), new BufferedBlockCipher(new SICBlockCipher(new AESEngine()))); ParametersWithIV cipherParameters = new ParametersWithIV(iesWithCipherParameters, iv.toArrayUnsafe()); engine.init(true, privParam, pubParam, cipherParameters); return engine; }
Example #5
Source File: RLPxConnectionFactory.java From cava with Apache License 2.0 | 5 votes |
private static EthereumIESEncryptionEngine forDecryption( SecretKey privateKey, PublicKey ephemeralPublicKey, Bytes iv, Bytes commonMac) { CipherParameters pubParam = new ECPublicKeyParameters(ephemeralPublicKey.asEcPoint(), CURVE); CipherParameters privParam = new ECPrivateKeyParameters(privateKey.bytes().toUnsignedBigInteger(), CURVE); BasicAgreement agreement = new ECDHBasicAgreement(); agreement.init(privParam); byte[] agreementValue = BigIntegers.asUnsignedByteArray(agreement.getFieldSize(), agreement.calculateAgreement(pubParam)); IESWithCipherParameters iesWithCipherParameters = new IESWithCipherParameters(new byte[0], new byte[0], 128, 128); EthereumIESEncryptionEngine.ECIESHandshakeKDFFunction kdf = new EthereumIESEncryptionEngine.ECIESHandshakeKDFFunction(1, new SHA256Digest()); kdf.init(new KDFParameters(agreementValue, iesWithCipherParameters.getDerivationV())); EthereumIESEncryptionEngine engine = new EthereumIESEncryptionEngine( agreement, kdf, new HMac(new SHA256Digest()), commonMac.toArrayUnsafe(), new BufferedBlockCipher(new SICBlockCipher(new AESEngine()))); ParametersWithIV cipherParameters = new ParametersWithIV(iesWithCipherParameters, iv.toArrayUnsafe()); engine.init(false, privParam, pubParam, cipherParameters); return engine; }
Example #6
Source File: RLPxConnectionFactory.java From incubator-tuweni with Apache License 2.0 | 4 votes |
private static EthereumIESEncryptionEngine forEncryption( PublicKey pubKey, Bytes iv, Bytes commonMac, KeyPair ephemeralKeyPair) { CipherParameters pubParam = new ECPublicKeyParameters(pubKey.asEcPoint(), CURVE); CipherParameters privParam = new ECPrivateKeyParameters(ephemeralKeyPair.secretKey().bytes().toUnsignedBigInteger(), CURVE); BasicAgreement agree = new ECDHBasicAgreement(); agree.init(privParam); BigInteger z = agree.calculateAgreement(pubParam); byte[] zbytes = BigIntegers.asUnsignedByteArray(agree.getFieldSize(), z); IESWithCipherParameters iesWithCipherParameters = new IESWithCipherParameters(new byte[0], new byte[0], 128, 128); // Initialise the KDF. EthereumIESEncryptionEngine.ECIESHandshakeKDFFunction kdf = new EthereumIESEncryptionEngine.ECIESHandshakeKDFFunction(1, new SHA256Digest()); kdf.init(new KDFParameters(zbytes, iesWithCipherParameters.getDerivationV())); EthereumIESEncryptionEngine engine = new EthereumIESEncryptionEngine( agree, kdf, new HMac(new SHA256Digest()), commonMac.toArrayUnsafe(), new BufferedBlockCipher(new SICBlockCipher(new AESEngine()))); ParametersWithIV cipherParameters = new ParametersWithIV(iesWithCipherParameters, iv.toArrayUnsafe()); engine.init(true, privParam, pubParam, cipherParameters); return engine; }