diff --git a/components/net/sf/briar/transport/PacketEncrypterImpl.java b/components/net/sf/briar/transport/PacketEncrypterImpl.java
index 5629bcae44831f2a2e0b707dffb13a5f2b28027d..4469a0f4e0ab53fdca391038b1154a603463b2d2 100644
--- a/components/net/sf/briar/transport/PacketEncrypterImpl.java
+++ b/components/net/sf/briar/transport/PacketEncrypterImpl.java
@@ -10,6 +10,7 @@ import javax.crypto.BadPaddingException;
 import javax.crypto.Cipher;
 import javax.crypto.IllegalBlockSizeException;
 import javax.crypto.SecretKey;
+import javax.crypto.ShortBufferException;
 import javax.crypto.spec.IvParameterSpec;
 
 class PacketEncrypterImpl extends FilterOutputStream
@@ -67,22 +68,35 @@ implements PacketEncrypter {
 
 	@Override
 	public void write(int b) throws IOException {
-		// FIXME: Encrypt into same buffer
-		byte[] ciphertext = packetCipher.update(new byte[] {(byte) b});
-		if(ciphertext != null) out.write(ciphertext);
+		byte[] buf = new byte[] {(byte) b};
+		try {
+			int i = packetCipher.update(buf, 0, buf.length, buf);
+			assert i <= 1;
+			if(i == 1) out.write(b);
+		} catch(ShortBufferException badCipher) {
+			throw new RuntimeException(badCipher);
+		}
 	}
 
 	@Override
 	public void write(byte[] b) throws IOException {
-		// FIXME: Encrypt into same buffer
-		byte[] ciphertext = packetCipher.update(b);
-		if(ciphertext != null) out.write(ciphertext);
+		try {
+			int i = packetCipher.update(b, 0, b.length, b);
+			assert i <= b.length;
+			out.write(b, 0, i);
+		} catch(ShortBufferException badCipher) {
+			throw new RuntimeException(badCipher);
+		}
 	}
 
 	@Override
 	public void write(byte[] b, int off, int len) throws IOException {
-		// FIXME: Encrypt into same buffer
-		byte[] ciphertext = packetCipher.update(b, off, len);
-		if(ciphertext != null) out.write(ciphertext);
+		try {
+			int i = packetCipher.update(b, off, len, b, off);
+			assert i <= len;
+			out.write(b, off, i);
+		} catch(ShortBufferException badCipher) {
+			throw new RuntimeException(badCipher);
+		}
 	}
 }