@Test public void testEncryptDecrypt_WithOutIv() throws InvalidCipherTextException { byte[] kdf = new byte[32]; SecureRandom prng = new SecureRandom(); prng.nextBytes(kdf); byte[] plainBytes = "01234567890123450123456789012345345".getBytes(); log.info("plain: {}", Hex.toHexString(plainBytes)); byte[] encData = AESEncrypt.encrypt(plainBytes, kdf); log.info("encrypt: {}", Hex.toHexString(encData)); byte[] plainData = AESEncrypt.decrypt(encData, kdf); log.info("decrypt: {}", Hex.toHexString(plainData)); assertArrayEquals(plainBytes, plainData); }
WALLET_PBKDF2_DKLEN, WALLET_PBKDF2_ALGORITHM); byte[] encData = AESEncrypt.encrypt( key.getPrivKeyBytes(), ByteUtil.parseBytes(kdfPass, 0, 16),
.getAsString()); byte[] priKey = AESEncrypt.decrypt( encData, ByteUtil.parseBytes(kdfPass, 0, 16), iv); this.key = ECKey.fromPrivate(priKey);
WALLET_PBKDF2_ALGORITHM); byte[] encData = AESEncrypt.encrypt( plainBytes, ByteUtil.parseBytes(kdfPass, 0, 16), iv); log.debug("encrypt: {}", Hex.toHexString(encData)); byte[] plainData = AESEncrypt.decrypt( encData, ByteUtil.parseBytes(kdfPass, 0, 16), iv); log.debug("decrypt: {}", Hex.toHexString(plainData));
@Test public void testEncryptDecrypt_WithIv() throws InvalidCipherTextException { byte[] plainBytes = "01234567890123450123456789012345345".getBytes(); log.info("plain: {}", Hex.toHexString(plainBytes)); String password = "Aa1234567890#"; log.info("password: {}", password); byte[] iv = new byte[16]; byte[] salt = new byte[32]; SecureRandom prng = new SecureRandom(); prng.nextBytes(iv); prng.nextBytes(salt); byte[] kdfPass = HashUtil.pbkdf2( password.getBytes(), salt, WALLET_PBKDF2_ITERATION, WALLET_PBKDF2_DKLEN, WALLET_PBKDF2_ALGORITHM); byte[] encData = AESEncrypt.encrypt( plainBytes, ByteUtil.parseBytes(kdfPass, 0, 16), iv); log.info("encrypt: {}", Hex.toHexString(encData)); byte[] plainData = AESEncrypt.decrypt( encData, ByteUtil.parseBytes(kdfPass, 0, 16), iv); log.info("decrypt: {}", Hex.toHexString(plainData)); assertArrayEquals(plainBytes, plainData); }
WALLET_PBKDF2_DKLEN, WALLET_PBKDF2_ALGORITHM); byte[] encData = AESEncrypt.encrypt( plainBytes, ByteUtil.parseBytes(kdfPass, 0, 16), log.info("encrypt: {}", Hex.toHexString(encData)); byte[] plainData = AESEncrypt.decrypt( encData, ByteUtil.parseBytes(kdfPass, 0, 16), iv); log.info("decrypt: {}", Hex.toHexString(plainData));