3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 10:15:52 +00:00

BIP38: Fix test using supplementary characters in the passphrase.

This commit is contained in:
Andreas Schildbach 2014-07-16 23:51:59 +02:00 committed by Mike Hearn
parent 4a45d4a27f
commit c6659bcf5f
2 changed files with 8 additions and 4 deletions

View File

@ -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");

View File

@ -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());
}