if (getCipher() != null ? !getCipher().equals(that.getCipher()) : that.getCipher() != null) { return false; if (getCiphertext() != null ? !getCiphertext().equals(that.getCiphertext()) : that.getCiphertext() != null) { return false; if (getCipherparams() != null ? !getCipherparams().equals(that.getCipherparams()) : that.getCipherparams() != null) { return false; if (getKdf() != null ? !getKdf().equals(that.getKdf()) : that.getKdf() != null) { return false; if (getKdfparams() != null ? !getKdfparams().equals(that.getKdfparams()) : that.getKdfparams() != null) { return false; return getMac() != null ? getMac().equals(that.getMac()) : that.getMac() == null;
walletFile.setAddress("0042e5d2a662eeaca8a7e828c174f98f35d8925b"); WalletFile.Crypto crypto = new WalletFile.Crypto(); crypto.setCipher("aes-128-ctr"); crypto.setCiphertext("df27e3db64aa18d984b6439443f73660643c2d119a6f0fa2fa9a6456fc802d75"); crypto.setCipherparams(cipherParams); crypto.setKdf("pbkdf2"); WalletFile.Aes128CtrKdfParams kdfParams = new WalletFile.Aes128CtrKdfParams(); kdfParams.setC(10240); kdfParams.setDklen(32); kdfParams.setSalt("ddc325335cda5567a1719313e73b4842511f3e4a837c9658eeb78e51ebe8c815"); crypto.setKdfparams(kdfParams); crypto.setMac("3dc888ae79cbb226ff9c455669f6cf2d79be72120f2298f6cb0d444fddc0aa3d"); walletFile.setCrypto(crypto); walletFile.setId("6a186c80-7797-cff2-bc2e-7c1d6a6cc76e");
byte[] mac = Numeric.hexStringToByteArray(crypto.getMac()); byte[] iv = Numeric.hexStringToByteArray(crypto.getCipherparams().getIv()); byte[] cipherText = Numeric.hexStringToByteArray(crypto.getCiphertext()); WalletFile.KdfParams kdfParams = crypto.getKdfparams(); if (kdfParams instanceof WalletFile.ScryptKdfParams) { WalletFile.ScryptKdfParams scryptKdfParams = (WalletFile.ScryptKdfParams) crypto.getKdfparams(); int dklen = scryptKdfParams.getDklen(); int n = scryptKdfParams.getN(); } else if (kdfParams instanceof WalletFile.Aes128CtrKdfParams) { WalletFile.Aes128CtrKdfParams aes128CtrKdfParams = (WalletFile.Aes128CtrKdfParams) crypto.getKdfparams(); int c = aes128CtrKdfParams.getC(); String prf = aes128CtrKdfParams.getPrf(); throw new CipherException("Unable to deserialize params: " + crypto.getKdf());
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof WalletFile)) { return false; } WalletFile that = (WalletFile) o; if (getAddress() != null ? !getAddress().equals(that.getAddress()) : that.getAddress() != null) { return false; } if (getCrypto() != null ? !getCrypto().equals(that.getCrypto()) : that.getCrypto() != null) { return false; } if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) { return false; } return version == that.version; }
@Test public void testParityNewAccountFromWallet() throws Exception { WalletFile walletFile = new WalletFile(); walletFile.setAddress("0x..."); WalletFile.Crypto crypto = new WalletFile.Crypto(); crypto.setCipher("CIPHER"); crypto.setCiphertext("CIPHERTEXT"); walletFile.setCrypto(crypto); WalletFile.CipherParams cipherParams = new WalletFile.CipherParams(); cipherParams.setIv("IV"); crypto.setCipherparams(cipherParams); crypto.setKdf("KDF"); WalletFile.ScryptKdfParams kdfParams = new WalletFile.ScryptKdfParams(); kdfParams.setDklen(32); kdfParams.setN(1); kdfParams.setP(10); kdfParams.setR(100); kdfParams.setSalt("SALT"); crypto.setKdfparams(kdfParams); crypto.setMac("MAC"); walletFile.setCrypto(crypto); walletFile.setId("cab06c9e-79a9-48ea-afc7-d3bdb3a59526"); walletFile.setVersion(1); web3j.parityNewAccountFromWallet(walletFile, "password").send(); //CHECKSTYLE:OFF verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_newAccountFromWallet\",\"params\":[{\"address\":\"0x...\",\"id\":\"cab06c9e-79a9-48ea-afc7-d3bdb3a59526\",\"version\":1,\"crypto\":{\"cipher\":\"CIPHER\",\"ciphertext\":\"CIPHERTEXT\",\"cipherparams\":{\"iv\":\"IV\"},\"kdf\":\"KDF\",\"kdfparams\":{\"dklen\":32,\"n\":1,\"p\":10,\"r\":100,\"salt\":\"SALT\"},\"mac\":\"MAC\"}},\"password\"],\"id\":1}"); //CHECKSTYLE:ON }
private static WalletFile createWalletFile( ECKeyPair ecKeyPair, byte[] cipherText, byte[] iv, byte[] salt, byte[] mac, int n, int p) { WalletFile walletFile = new WalletFile(); walletFile.setAddress(Keys.getAddress(ecKeyPair)); WalletFile.Crypto crypto = new WalletFile.Crypto(); crypto.setCipher(CIPHER); crypto.setCiphertext(Numeric.toHexStringNoPrefix(cipherText)); WalletFile.CipherParams cipherParams = new WalletFile.CipherParams(); cipherParams.setIv(Numeric.toHexStringNoPrefix(iv)); crypto.setCipherparams(cipherParams); crypto.setKdf(SCRYPT); WalletFile.ScryptKdfParams kdfParams = new WalletFile.ScryptKdfParams(); kdfParams.setDklen(DKLEN); kdfParams.setN(n); kdfParams.setP(p); kdfParams.setR(R); kdfParams.setSalt(Numeric.toHexStringNoPrefix(salt)); crypto.setKdfparams(kdfParams); crypto.setMac(Numeric.toHexStringNoPrefix(mac)); walletFile.setCrypto(crypto); walletFile.setId(UUID.randomUUID().toString()); walletFile.setVersion(CURRENT_VERSION); return walletFile; }
static void validate(WalletFile walletFile) throws CipherException { WalletFile.Crypto crypto = walletFile.getCrypto(); if (walletFile.getVersion() != CURRENT_VERSION) { throw new CipherException("Wallet version is not supported"); } if (!crypto.getCipher().equals(CIPHER)) { throw new CipherException("Wallet cipher is not supported"); } if (!crypto.getKdf().equals(AES_128_CTR) && !crypto.getKdf().equals(SCRYPT)) { throw new CipherException("KDF type is not supported"); } }
@Override public int hashCode() { int result = getCipher() != null ? getCipher().hashCode() : 0; result = 31 * result + (getCiphertext() != null ? getCiphertext().hashCode() : 0); result = 31 * result + (getCipherparams() != null ? getCipherparams().hashCode() : 0); result = 31 * result + (getKdf() != null ? getKdf().hashCode() : 0); result = 31 * result + (getKdfparams() != null ? getKdfparams().hashCode() : 0); result = 31 * result + (getMac() != null ? getMac().hashCode() : 0); return result; }