From c6659bcf5f611c56975e88f0d6841e1d6d60dd2f Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Wed, 16 Jul 2014 23:51:59 +0200 Subject: [PATCH] BIP38: Fix test using supplementary characters in the passphrase. --- .../java/com/google/bitcoin/crypto/BIP38PrivateKey.java | 3 +-- .../com/google/bitcoin/crypto/BIP38PrivateKeyTest.java | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/crypto/BIP38PrivateKey.java b/core/src/main/java/com/google/bitcoin/crypto/BIP38PrivateKey.java index f389f52a..d45a7cca 100644 --- a/core/src/main/java/com/google/bitcoin/crypto/BIP38PrivateKey.java +++ b/core/src/main/java/com/google/bitcoin/crypto/BIP38PrivateKey.java @@ -96,8 +96,7 @@ public class BIP38PrivateKey extends VersionedChecksummedBytes { private ECKey decryptNoEC(String normalizedPassphrase) { try { - final byte[] passwd = normalizedPassphrase.getBytes(Charsets.UTF_8); - byte[] derived = SCrypt.scrypt(passwd, addressHash, 16384, 8, 8, 64); + byte[] derived = SCrypt.scrypt(normalizedPassphrase.getBytes(Charsets.UTF_8), addressHash, 16384, 8, 8, 64); byte[] key = Arrays.copyOfRange(derived, 32, 64); SecretKeySpec keyspec = new SecretKeySpec(key, "AES"); diff --git a/core/src/test/java/com/google/bitcoin/crypto/BIP38PrivateKeyTest.java b/core/src/test/java/com/google/bitcoin/crypto/BIP38PrivateKeyTest.java index 4070b85d..34527012 100644 --- a/core/src/test/java/com/google/bitcoin/crypto/BIP38PrivateKeyTest.java +++ b/core/src/test/java/com/google/bitcoin/crypto/BIP38PrivateKeyTest.java @@ -54,11 +54,16 @@ public class BIP38PrivateKeyTest { } @Test - @Ignore("Test disabled because Java doesn't seem to do unicode the same way as other platforms") public void bip38testvector_noCompression_noEcMultiply_test3() throws Exception { BIP38PrivateKey encryptedKey = new BIP38PrivateKey(MAINNET, "6PRW5o9FLp4gJDDVqJQKJFTpMvdsSGJxMYHtHaQBF3ooa8mwD69bapcDQn"); - ECKey key = encryptedKey.decrypt("\u03d2\u0301\u0000\u00010400\u0001f4a9"); + StringBuilder passphrase = new StringBuilder(); + passphrase.appendCodePoint(0x03d2); // GREEK UPSILON WITH HOOK + passphrase.appendCodePoint(0x0301); // COMBINING ACUTE ACCENT + passphrase.appendCodePoint(0x0000); // NULL + passphrase.appendCodePoint(0x010400); // DESERET CAPITAL LETTER LONG I + passphrase.appendCodePoint(0x01f4a9); // PILE OF POO + ECKey key = encryptedKey.decrypt(passphrase.toString()); assertEquals("5Jajm8eQ22H3pGWLEVCXyvND8dQZhiQhoLJNKjYXk9roUFTMSZ4", key.getPrivateKeyEncoded(MAINNET) .toString()); }