public static EncryptionResult fromByteArray(byte[] array) { EncryptionResult result = new EncryptionResult(); ByteBuffer bb = ByteBuffer.wrap(array); int saltSize = bb.getInt(); int ivSize = bb.getInt(); int cipherSize = bb.getInt(); result.salt = new byte[saltSize]; result.iv = new byte[ivSize]; result.cipher = new byte[cipherSize]; bb.get(result.salt); bb.get(result.iv); bb.get(result.cipher); return result; } }
public static EncryptionResult fromByteArray(byte[] array) { EncryptionResult result = new EncryptionResult(); ByteBuffer bb = ByteBuffer.wrap(array); int saltSize = bb.getInt(); int ivSize = bb.getInt(); int cipherSize = bb.getInt(); result.salt = new byte[saltSize]; result.iv = new byte[ivSize]; result.cipher = new byte[cipherSize]; bb.get(result.salt); bb.get(result.iv); bb.get(result.cipher); return result; } }
public EncryptionResult encrypt(byte[] plain) throws Exception { byte[] salt = new byte[saltSize]; SecureRandom rnd = new SecureRandom(); rnd.nextBytes(salt); SecretKey tmp = getKeyFromPassword(new String(passPhrase), salt); SecretKey secret = new SecretKeySpec(tmp.getEncoded(), alg); Cipher ecipher = Cipher.getInstance(transformation); ecipher.init(Cipher.ENCRYPT_MODE, secret); return new EncryptionResult(salt, ecipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV(), ecipher.doFinal(plain)); }
public EncryptionResult encrypt(byte[] plain) throws Exception { byte[] salt = new byte[saltSize]; SecureRandom rnd = new SecureRandom(); rnd.nextBytes(salt); SecretKey tmp = getKeyFromPassword(new String(passPhrase), salt); SecretKey secret = new SecretKeySpec(tmp.getEncoded(), alg); Cipher ecipher = Cipher.getInstance(transformation); ecipher.init(Cipher.ENCRYPT_MODE, secret); EncryptionResult atom = new EncryptionResult(salt, ecipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV(), ecipher.doFinal(plain)); return atom; }