@Test public void ecdhDecryptionTest() { byte [] alicePrivateKey = Utils.HEX.decode("0000000000000000000000000000000000000000000000000000000000000001"); byte [] alicePublicKey = Utils.HEX.decode("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"); ECKey bobKeyPair = ECKey.fromPrivate(Utils.HEX.decode("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140")); byte [] encryptedSecret = Utils.HEX.decode("eac5bcd6eb85074759e0261497428c9b3725d3b9ec4d739a842116277c6ace81549089be0d11a54ee09a99dcf7ac695a8ea56d41bf0b62def90b6f78f8b0aca9"); KeyCrypterECDH aliceKeyExchangeCrypter = new KeyCrypterECDH(); KeyParameter aliceKeyParameter = aliceKeyExchangeCrypter.deriveKey(alicePrivateKey, bobKeyPair.getPubKey()); assertEquals("fbd27dbb9e7f471bf3de3704a35e884e37d35c676dc2cc8c3cc574c3962376d2", Utils.HEX.encode(aliceKeyParameter.getKey())); EncryptedData encryptedAliceData = aliceKeyExchangeCrypter.encrypt(secret.getBytes(), Arrays.copyOfRange(encryptedSecret, 0, 16), aliceKeyParameter); ByteArrayOutputStream baos = new ByteArrayOutputStream(encryptedAliceData.encryptedBytes.length + encryptedAliceData.initialisationVector.length); assertArrayEquals(Arrays.copyOfRange(encryptedSecret, 0, 16), encryptedAliceData.initialisationVector); try { baos.write(encryptedAliceData.initialisationVector); baos.write(encryptedAliceData.encryptedBytes); } catch (IOException x) { fail(); } assertArrayEquals("they should be the same data", encryptedSecret, baos.toByteArray()); KeyCrypterECDH bobKeyExchangeCrypter = new KeyCrypterECDH(); KeyParameter bobKeyParameter = bobKeyExchangeCrypter.deriveKey(bobKeyPair.getPrivKeyBytes(), alicePublicKey); EncryptedData encryptedData = new EncryptedData(Arrays.copyOfRange(encryptedSecret, 0, 16), Arrays.copyOfRange(encryptedSecret, 16, encryptedSecret.length)); byte[] encryptedBobData = bobKeyExchangeCrypter.decrypt(encryptedData, bobKeyParameter); String decryptedSecret = new String(encryptedBobData); assertEquals("they should be the same string", secret, decryptedSecret); }
@Override public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException { throw new UnsupportedOperationException("use deriveKey(ECKey, ECKey) instead"); }
KeyCrypterECDH extends KeyCrypterAESCBC { @Override public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException { throw new UnsupportedOperationException("use deriveKey(ECKey, ECKey) instead"); } }
KeyCrypterECDH extends KeyCrypterAESCBC { @Override public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException { throw new UnsupportedOperationException("use deriveKey(ECKey, ECKey) instead"); }  }
KeyCrypterECDH extends KeyCrypterAESCBC { @Override public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException { throw new UnsupportedOperationException("use deriveKey(ECKey, ECKey) instead"); }  @Override KeyParameter deriveKey(CharSequence password); KeyParameter deriveKey(ECKey secretKey, ECKey publicKey); @Override EncryptionType getUnderstoodEncryptionType(); @Override String toString(); }
KeyCrypterECDH extends KeyCrypterAESCBC { @Override public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException { throw new UnsupportedOperationException("use deriveKey(ECKey, ECKey) instead"); }  @Override KeyParameter deriveKey(CharSequence password); KeyParameter deriveKey(ECKey secretKey, ECKey publicKey); @Override EncryptionType getUnderstoodEncryptionType(); @Override String toString();  }