diff --git a/briar-core/src/org/briarproject/crypto/Sec1PrivateKey.java b/briar-core/src/org/briarproject/crypto/Sec1PrivateKey.java
index 2cf5ab782ef4fcb6178ceeeb25b80862856e7ab7..256001dbaf74f66e13b572e59473c89f21174c58 100644
--- a/briar-core/src/org/briarproject/crypto/Sec1PrivateKey.java
+++ b/briar-core/src/org/briarproject/crypto/Sec1PrivateKey.java
@@ -17,7 +17,7 @@ class Sec1PrivateKey implements PrivateKey {
 	public byte[] getEncoded() {
 		byte[] encodedKey = new byte[bytesPerInt];
 		byte[] d = key.getD().toByteArray();
-		Sec1Utils.convertToFixedLength(d, encodedKey, bytesPerInt, 0);
+		Sec1Utils.convertToFixedLength(d, encodedKey, 0, bytesPerInt);
 		return encodedKey;
 	}
 
diff --git a/briar-core/src/org/briarproject/crypto/Sec1PublicKey.java b/briar-core/src/org/briarproject/crypto/Sec1PublicKey.java
index 0b749384afd4b66b109f080f4b45fd4eed7914a8..eefdfde74b01714fb056af6fb5ddbbdac707da91 100644
--- a/briar-core/src/org/briarproject/crypto/Sec1PublicKey.java
+++ b/briar-core/src/org/briarproject/crypto/Sec1PublicKey.java
@@ -24,10 +24,10 @@ class Sec1PublicKey implements PublicKey {
 		byte[] encodedKey = new byte[publicKeyBytes];
 		encodedKey[0] = 4;
 		byte[] x = key.getQ().getX().toBigInteger().toByteArray();
-		Sec1Utils.convertToFixedLength(x, encodedKey, bytesPerInt, 1);
+		Sec1Utils.convertToFixedLength(x, encodedKey, 1, bytesPerInt);
 		byte[] y = key.getQ().getY().toBigInteger().toByteArray();
-		Sec1Utils.convertToFixedLength(y, encodedKey, bytesPerInt,
-				1 + bytesPerInt);
+		Sec1Utils.convertToFixedLength(y, encodedKey, 1 + bytesPerInt,
+				bytesPerInt);
 		return encodedKey;
 	}
 
diff --git a/briar-core/src/org/briarproject/crypto/Sec1Utils.java b/briar-core/src/org/briarproject/crypto/Sec1Utils.java
index b0f14ca1ba71464a9341d6daa8cac123eab73834..23e1f865267933d672a4cc2d7f7cf75566bc19eb 100644
--- a/briar-core/src/org/briarproject/crypto/Sec1Utils.java
+++ b/briar-core/src/org/briarproject/crypto/Sec1Utils.java
@@ -2,11 +2,12 @@ package org.briarproject.crypto;
 
 class Sec1Utils {
 
-	static void convertToFixedLength(byte[] src, byte[] dest, int destLen,
-			int destOff) {
+	static void convertToFixedLength(byte[] src, byte[] dest, int destOff,
+			int destLen) {
 		if(src.length < destLen) {
-			destOff += destLen - src.length;
-			System.arraycopy(src, 0, dest, destOff, src.length);
+			int padding = destLen - src.length;
+			for(int i = destOff; i < destOff + padding; i++) dest[i] = 0;
+			System.arraycopy(src, 0, dest, destOff + padding, src.length);
 		} else {
 			int srcOff = src.length - destLen;
 			System.arraycopy(src, srcOff, dest, destOff, destLen);