IESEngine iesEngine = new IESEngine( new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA256Digest()), gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom())); iesEngine.init(true, p1.getPrivate(), p2.getPublic(), parametersWithIV); 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 BufferedBlockCipher(new SICBlockCipher(aesFastEngine))); decryptorIES_Engine.init(false, p2.getPrivate(), p1.getPublic(), parametersWithIV); byte[] orig = decryptorIES_Engine.processBlock(cipher, 0, cipher.length);
/** * Initialise the decryptor. * * @param publicKey the recipient's/sender's public key parameters * @param params encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher. * @param ephemeralKeyPairGenerator the ephemeral key pair generator to use. */ public void init(AsymmetricKeyParameter publicKey, CipherParameters params, EphemeralKeyPairGenerator ephemeralKeyPairGenerator) { this.forEncryption = true; this.pubParam = publicKey; this.keyPairGenerator = ephemeralKeyPairGenerator; extractParams(params); }
public ECIES() { super(new IESEngine(new ECDHBasicAgreement(), new KDF2BytesGenerator(DigestFactory.createSHA1()), new HMac(DigestFactory.createSHA1()))); } }
engine.init(true, otherKeyParameter, key, params); engine.init(false, key, otherKeyParameter, params); return engine.processBlock(in, 0, in.length); engine.init(key, params, kGen); return engine.processBlock(in, 0, in.length); engine.init(key, params, new ECIESPublicKeyParser(ecParams)); return engine.processBlock(in, 0, in.length);
public byte[] processBlock( byte[] in, int inOff, int inLen) throws InvalidCipherTextException { agree.init(privParam); BigInteger z = agree.calculateAgreement(pubParam); // TODO Is a fixed length result expected? byte[] zBytes = BigIntegers.asUnsignedByteArray(z); return forEncryption ? encryptBlock(in, inOff, inLen, zBytes) : decryptBlock(in, inOff, inLen, zBytes); } }
protected byte[] engineDoFinal( byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException { if (inputLen != 0) { buffer.write(input, inputOffset, inputLen); } try { byte[] buf = buffer.toByteArray(); buffer.reset(); return cipher.processBlock(buf, 0, buf.length); } catch (InvalidCipherTextException e) { throw new BadPaddingException(e.getMessage()); } }
byte[] buf = generateKdfBytes(kParam, inLen + (macKeySize / 8)); byte[] buf = generateKdfBytes(kParam, (cipherKeySize / 8) + (macKeySize / 8));
public IES() { super(new IESEngine(new DHBasicAgreement(), new KDF2BytesGenerator(DigestFactory.createSHA1()), new HMac(DigestFactory.createSHA1()))); } }
engine.init(true, otherKeyParameter, key, params); engine.init(false, key, otherKeyParameter, params); return engine.processBlock(in, 0, in.length); engine.init(key, params, kGen); return engine.processBlock(in, 0, in.length); engine.init(key, params, new DHIESPublicKeyParser(((DHKeyParameters)key).getParameters())); return engine.processBlock(in, 0, in.length);
? encryptBlock(in, inOff, inLen) : decryptBlock(in, inOff, inLen);
protected int engineDoFinal( byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws IllegalBlockSizeException, BadPaddingException { if (inputLen != 0) { buffer.write(input, inputOffset, inputLen); } try { byte[] buf = buffer.toByteArray(); buffer.reset(); buf = cipher.processBlock(buf, 0, buf.length); System.arraycopy(buf, 0, output, outputOffset, buf.length); return buf.length; } catch (InvalidCipherTextException e) { throw new BadPaddingException(e.getMessage()); } }
byte[] buf = generateKdfBytes(kParam, inLen + (macKeySize / 8)); byte[] buf = generateKdfBytes(kParam, (cipherKeySize / 8) + (macKeySize / 8));
IESEngine iesEngine = new IESEngine( new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA256Digest()), gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom())); iesEngine.init(myKey.getPublic(), parametersWithIV, kGen); 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 BufferedBlockCipher(new SICBlockCipher(aesFastEngine))); decryptorIES_Engine.init(myKey.getPrivate(), parametersWithIV, new ECIESPublicKeyParser(ECKey.CURVE)); byte[] orig = decryptorIES_Engine.processBlock(cipher, 0, cipher.length);
public ECIESwithCipher(BlockCipher cipher, int ivLength) { super(new IESEngine(new ECDHBasicAgreement(), new KDF2BytesGenerator(DigestFactory.createSHA1()), new HMac(DigestFactory.createSHA1()), new PaddedBufferedBlockCipher(cipher)), ivLength); } }
/** * Initialise the encryptor. * * @param privateKey the recipient's private key. * @param params encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher. * @param publicKeyParser the parser for reading the ephemeral public key. */ public void init(AsymmetricKeyParameter privateKey, CipherParameters params, KeyParser publicKeyParser) { this.forEncryption = false; this.privParam = privateKey; this.keyParser = publicKeyParser; extractParams(params); }
IESEngine iesEngine = new IESEngine( new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA256Digest()), gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom())); iesEngine.init(true, p1.getPrivate(), p2.getPublic(), parametersWithIV); 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 BufferedBlockCipher(new SICBlockCipher(aesFastEngine))); decryptorIES_Engine.init(false, p2.getPrivate(), p1.getPublic(), parametersWithIV); byte[] orig = decryptorIES_Engine.processBlock(cipher, 0, cipher.length);
public ECIES() { super(new IESEngine( new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()))); } }
/** * Initialise the encryptor. * * @param forEncryption whether or not this is encryption/decryption. * @param privParam our private key parameters * @param pubParam the recipient's/sender's public key parameters * @param params encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher. */ public void init( boolean forEncryption, CipherParameters privParam, CipherParameters pubParam, CipherParameters params) { this.forEncryption = forEncryption; this.privParam = privParam; this.pubParam = pubParam; this.V = new byte[0]; extractParams(params); }
public BrokenIES() { super(new IESEngine( new DHBasicAgreement(), new BrokenKDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()))); } }