List of usage examples for org.bouncycastle.crypto.params KDFParameters KDFParameters
public KDFParameters(byte[] shared, byte[] iv)
From source file:edu.biu.scapi.primitives.kdf.bc.BcKdfISO18033.java
License:Open Source License
/** * Generates the bc related parameters of type DerivationParameters * @param shared the input key /* ww w. j av a 2 s .c o m*/ * @param iv */ private DerivationParameters generateParameters(byte[] shared, byte[] iv) { if (iv == null) {//iv is not provided return new ISO18033KDFParameters(shared); } else { //iv is provided. Passes to the KDFParameters return new KDFParameters(shared, iv); } }
From source file:org.ethereum.crypto.ECIESTest.java
License:Open Source License
@Test public void testKDF() { ConcatKDFBytesGenerator kdf = new ConcatKDFBytesGenerator(new SHA256Digest()); kdf.init(new KDFParameters("Hello".getBytes(), new byte[0])); byte[] bytes = new byte[2]; kdf.generateBytes(bytes, 0, bytes.length); assertArrayEquals(new byte[] { -66, -89 }, bytes); }
From source file:org.ethereum.crypto.EthereumIESEngine.java
License:Open Source License
public byte[] processBlock(byte[] in, int inOff, int inLen, byte[] macData) throws InvalidCipherTextException { if (forEncryption) { if (keyPairGenerator != null) { EphemeralKeyPair ephKeyPair = keyPairGenerator.generate(); this.privParam = ephKeyPair.getKeyPair().getPrivate(); this.v = ephKeyPair.getEncodedPublicKey(); }/* www. j a va2s . c o m*/ } else { if (keyParser != null) { ByteArrayInputStream bIn = new ByteArrayInputStream(in, inOff, inLen); try { this.pubParam = keyParser.readKey(bIn); } catch (IOException e) { throw new InvalidCipherTextException( "unable to recover ephemeral public key: " + e.getMessage(), e); } int encLength = (inLen - bIn.available()); this.v = Arrays.copyOfRange(in, inOff, inOff + encLength); } } // Compute the common value and convert to byte array. agree.init(privParam); BigInteger z = agree.calculateAgreement(pubParam); byte[] Z = BigIntegers.asUnsignedByteArray(agree.getFieldSize(), z); // Create input to KDF. byte[] vz; // if (v.length != 0) // { // VZ = new byte[v.length + Z.length]; // System.arraycopy(v, 0, VZ, 0, v.length); // System.arraycopy(Z, 0, VZ, v.length, Z.length); // } // else { vz = Z; } // Initialise the KDF. DerivationParameters kdfParam; if (kdf instanceof MGF1BytesGeneratorExt) { kdfParam = new MGFParameters(vz); } else { kdfParam = new KDFParameters(vz, param.getDerivationV()); } kdf.init(kdfParam); return forEncryption ? encryptBlock(in, inOff, inLen, macData) : decryptBlock(in, inOff, inLen, macData); }