@Test public void testDecrypt() { thrown.expect(TokenException.class); thrown.expectMessage(Messages.WALLET_INVALID_PASSWORD); Crypto crypto = Crypto.createPBKDF2Crypto(SampleKey.PASSWORD, prvKeyBytes); byte[] result = crypto.decrypt(SampleKey.PASSWORD); assertArrayEquals(prvKeyBytes, result); crypto.decrypt(SampleKey.WRONG_PASSWORD); assertTrue("Should return in early statements", false); }
public byte[] decrypt(String password) { byte[] derivedKey = getCachedDerivedKey(password); byte[] iv = NumericUtil.hexToBytes(this.getCipherparams().getIv()); byte[] encrypted = NumericUtil.hexToBytes(this.getCiphertext()); return decrypt(derivedKey, iv, encrypted); }
Crypto { public byte[] decrypt(String password) { byte[] derivedKey = getCachedDerivedKey(password); byte[] iv = NumericUtil.hexToBytes(this.getCipherparams().getIv()); byte[] encrypted = NumericUtil.hexToBytes(this.getCiphertext()); return decrypt(derivedKey, iv, encrypted); } }
Crypto { public byte[] decrypt(String password) { byte[] derivedKey = getCachedDerivedKey(password); byte[] iv = NumericUtil.hexToBytes(this.getCipherparams().getIv()); byte[] encrypted = NumericUtil.hexToBytes(this.getCiphertext()); return decrypt(derivedKey, iv, encrypted); } Crypto(); }
Crypto { public byte[] decrypt(String password) { byte[] derivedKey = getCachedDerivedKey(password); byte[] iv = NumericUtil.hexToBytes(this.getCipherparams().getIv()); byte[] encrypted = NumericUtil.hexToBytes(this.getCiphertext()); return decrypt(derivedKey, iv, encrypted); } Crypto(); static Crypto createPBKDF2Crypto(String password, byte[] origin); static Crypto createPBKDF2CryptoWithKDFCached(String password, byte[] origin); static Crypto createSCryptCrypto(String password, byte[] origin); boolean verifyPassword(String password); void cacheDerivedKey(String password); void clearCachedDerivedKey(); void validate(); byte[] decrypt(String password); EncPair deriveEncPair(String password, byte[] origin); byte[] decryptEncPair(String password, EncPair encPair); @JsonProperty(required = true) String getCiphertext(); @JsonProperty(required = true) CipherParams getCipherparams(); @JsonProperty(required = true) String getMac(); @JsonProperty(required = true) String getCipher(); @JsonProperty(required = true) String getKdf(); @JsonProperty(required = true) T getKdfparams(); void setCiphertext(String ciphertext); void setMac(String mac); void setCipher(String cipher); void setCipherparams(CipherParams cipherparams); void setKdf(String kdf); void setKdfparams(T kdfparams); @Override boolean equals(Object o); @Override int hashCode(); }
Crypto { public byte[] decrypt(String password) { byte[] derivedKey = getCachedDerivedKey(password); byte[] iv = NumericUtil.hexToBytes(this.getCipherparams().getIv()); byte[] encrypted = NumericUtil.hexToBytes(this.getCiphertext()); return decrypt(derivedKey, iv, encrypted); } Crypto(); static Crypto createPBKDF2Crypto(String password, byte[] origin); static Crypto createPBKDF2CryptoWithKDFCached(String password, byte[] origin); static Crypto createSCryptCrypto(String password, byte[] origin); boolean verifyPassword(String password); void cacheDerivedKey(String password); void clearCachedDerivedKey(); void validate(); byte[] decrypt(String password); EncPair deriveEncPair(String password, byte[] origin); byte[] decryptEncPair(String password, EncPair encPair); @JsonProperty(required = true) String getCiphertext(); @JsonProperty(required = true) CipherParams getCipherparams(); @JsonProperty(required = true) String getMac(); @JsonProperty(required = true) String getCipher(); @JsonProperty(required = true) String getKdf(); @JsonProperty(required = true) T getKdfparams(); void setCiphertext(String ciphertext); void setMac(String mac); void setCipher(String cipher); void setCipherparams(CipherParams cipherparams); void setKdf(String kdf); void setKdfparams(T kdfparams); @Override boolean equals(Object o); @Override int hashCode();  }