byte[] tmp = new byte[40];
System.arraycopy (passfactor, 0, tmp, 0, 32);
System.arraycopy (ownentropy, 0, tmp, 32, 8);
passfactor = Hash.hash (tmp);
}
ECKeyPair kp = new ECKeyPair (passfactor, true);
byte[] salt = new byte[12];
System.arraycopy (store, 3, salt, 0, 12);
byte[] derived = SCrypt.generate (kp.getPublic (), salt, 1024, 1, 1, 64);
byte[] aeskey = new byte[32];
System.arraycopy (derived, 32, aeskey, 0, 32);
SecretKeySpec keyspec = new SecretKeySpec (aeskey, "AES");
Cipher cipher = Cipher.getInstance ("AES/ECB/NoPadding", "BC");
cipher.init (Cipher.DECRYPT_MODE, keyspec);
byte[] encrypted = new byte[16];
System.arraycopy (store, 23, encrypted, 0, 16);
byte[] decrypted2 = cipher.doFinal (encrypted);
for ( int i = 0; i < 16; ++i )
{
decrypted2[i] ^= derived[i + 16];
}
System.arraycopy (store, 15, encrypted, 0, 8);
System.arraycopy (decrypted2, 0, encrypted, 8, 8);
byte[] decrypted1 = cipher.doFinal (encrypted);
for ( int i = 0; i < 16; ++i )
{
decrypted1[i] ^= derived[i];
}
byte[] seed = new byte[24];
System.arraycopy (decrypted1, 0, seed, 0, 16);
System.arraycopy (decrypted2, 8, seed, 16, 8);
BigInteger priv =
new BigInteger (1, passfactor).multiply (new BigInteger (1, Hash.hash (seed))).remainder (SECNamedCurves.getByName ("secp256k1").getN ());
kp = new ECKeyPair (priv, compressed);
byte[] acs = Hash.hash (new Address (network, kp.getAddress ()).toString ().getBytes ("US-ASCII"));
byte[] check = new byte[4];
System.arraycopy (acs, 0, check, 0, 4);
if ( !Arrays.equals (check, addressHash) )
{
throw new ValidationException ("failed to decrpyt");