/** * Decrypts the <code>CommunicationPacket</code> inside this packet. * @throws DataFormatException * @throws MalformedPacketException */ private CommunicationPacket decrypt(I2PSession i2pSession) throws DataFormatException, MalformedPacketException { PrivateKey privateKey = i2pSession.getDecryptionKey(); byte[] decryptedData = Util.decrypt(payload, privateKey); return CommunicationPacket.createPacket(decryptedData); } }
/** Only accepts <code>ElGamalPrivateKey</code>s. The public key is not used. */ @Override public byte[] decrypt(byte[] data, PublicKey publicKey, PrivateKey privateKey) throws GeneralSecurityException { if (data == null) return null; ElGamalPrivateKey elGamalKey = castToElGamal(privateKey); try { net.i2p.data.PrivateKey i2pPrivateKey = elGamalKey.getI2PKey(); return Util.decrypt(data, i2pPrivateKey); } catch (DataFormatException e) { byte[] shortenedData = data.length>10?Arrays.copyOf(data, 10):data; throw new KeyException("Can't decrypt data: " + Arrays.toString(shortenedData) + " (only the first 10 elements are shown).", e); } }