/** * Encrypt a stream of plaintext given a context and IV * @param out ciphertext * @param in plaintet * @param context * @param iv * @throws IOException */ public static void encrypt(OutputStream out, InputStream in, Context context, byte[] iv) throws IOException { Encryptor e = context.getCipher().getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); // can be null e.reset(); encrypt(out, in, e); }
/** * Encrypt a block of plaintext * @param out ciphertext * @param src plaintext * @param offset * @param length * @param context * @param iv * @throws IOException */ public static void encrypt(OutputStream out, byte[] src, int offset, int length, Context context, byte[] iv) throws IOException { Encryptor e = context.getCipher().getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); // can be null e.reset(); encrypt(out, src, offset, length, e); }
private void checkTransformSymmetry(byte[] keyBytes, byte[] iv, byte[] plaintext) throws Exception { LOG.info("checkTransformSymmetry: AES, plaintext length = " + plaintext.length); Configuration conf = HBaseConfiguration.create(); String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES); Cipher aes = Encryption.getCipher(conf, algorithm); Key key = new SecretKeySpec(keyBytes, algorithm); Encryptor e = aes.getEncryptor(); e.setKey(key); e.setIv(iv); e.reset(); ByteArrayOutputStream encOut = new ByteArrayOutputStream(); Encryption.encrypt(encOut, plaintext, 0, plaintext.length, e); byte[] encrypted = encOut.toByteArray(); Decryptor d = aes.getDecryptor(); d.setKey(key); d.setIv(iv); d.reset(); ByteArrayInputStream encIn = new ByteArrayInputStream(encrypted); ByteArrayOutputStream decOut = new ByteArrayOutputStream(); Encryption.decrypt(decOut, encIn, plaintext.length, d); byte[] result = decOut.toByteArray(); assertEquals("Decrypted result has different length than plaintext", result.length, plaintext.length); assertTrue("Transformation was not symmetric", Bytes.equals(result, plaintext)); }
encryptor.reset();
/** * Encrypt a stream of plaintext given a context and IV * @param out ciphertext * @param in plaintet * @param context * @param iv * @throws IOException */ public static void encrypt(OutputStream out, InputStream in, Context context, byte[] iv) throws IOException { Encryptor e = context.getCipher().getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); // can be null e.reset(); encrypt(out, in, e); }
/** * Encrypt a stream of plaintext given a context and IV * @param out ciphertext * @param in plaintet * @param context * @param iv * @throws IOException */ public static void encrypt(OutputStream out, InputStream in, Context context, byte[] iv) throws IOException { Encryptor e = context.getCipher().getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); // can be null e.reset(); encrypt(out, in, e); }
/** * Encrypt a stream of plaintext given a context and IV * @param out ciphertext * @param in plaintet * @param context * @param iv * @throws IOException */ public static void encrypt(OutputStream out, InputStream in, Context context, byte[] iv) throws IOException { Encryptor e = context.getCipher().getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); // can be null e.reset(); encrypt(out, in, e); }
/** * Encrypt a block of plaintext * @param out ciphertext * @param src plaintext * @param offset * @param length * @param context * @param iv * @throws IOException */ public static void encrypt(OutputStream out, byte[] src, int offset, int length, Context context, byte[] iv) throws IOException { Encryptor e = context.getCipher().getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); // can be null e.reset(); encrypt(out, src, offset, length, e); }
/** * Encrypt a block of plaintext * @param out ciphertext * @param src plaintext * @param offset * @param length * @param context * @param iv * @throws IOException */ public static void encrypt(OutputStream out, byte[] src, int offset, int length, Context context, byte[] iv) throws IOException { Encryptor e = context.getCipher().getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); // can be null e.reset(); encrypt(out, src, offset, length, e); }
/** * Encrypt a block of plaintext * @param out ciphertext * @param src plaintext * @param offset * @param length * @param context * @param iv * @throws IOException */ public static void encrypt(OutputStream out, byte[] src, int offset, int length, Context context, byte[] iv) throws IOException { Encryptor e = context.getCipher().getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); // can be null e.reset(); encrypt(out, src, offset, length, e); }
private void checkTransformSymmetry(byte[] keyBytes, byte[] iv, byte[] plaintext) throws Exception { LOG.info("checkTransformSymmetry: AES, plaintext length = " + plaintext.length); Configuration conf = HBaseConfiguration.create(); String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES); Cipher aes = Encryption.getCipher(conf, algorithm); Key key = new SecretKeySpec(keyBytes, algorithm); Encryptor e = aes.getEncryptor(); e.setKey(key); e.setIv(iv); e.reset(); ByteArrayOutputStream encOut = new ByteArrayOutputStream(); Encryption.encrypt(encOut, plaintext, 0, plaintext.length, e); byte[] encrypted = encOut.toByteArray(); Decryptor d = aes.getDecryptor(); d.setKey(key); d.setIv(iv); d.reset(); ByteArrayInputStream encIn = new ByteArrayInputStream(encrypted); ByteArrayOutputStream decOut = new ByteArrayOutputStream(); Encryption.decrypt(decOut, encIn, plaintext.length, d); byte[] result = decOut.toByteArray(); assertEquals("Decrypted result has different length than plaintext", result.length, plaintext.length); assertTrue("Transformation was not symmetric", Bytes.equals(result, plaintext)); }
encryptor.reset();
private void checkTransformSymmetry(byte[] keyBytes, byte[] iv, byte[] plaintext) throws Exception { LOG.info("checkTransformSymmetry: AES, plaintext length = " + plaintext.length); Configuration conf = HBaseConfiguration.create(); String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES); Cipher aes = Encryption.getCipher(conf, algorithm); Key key = new SecretKeySpec(keyBytes, algorithm); Encryptor e = aes.getEncryptor(); e.setKey(key); e.setIv(iv); e.reset(); ByteArrayOutputStream encOut = new ByteArrayOutputStream(); Encryption.encrypt(encOut, plaintext, 0, plaintext.length, e); byte[] encrypted = encOut.toByteArray(); Decryptor d = aes.getDecryptor(); d.setKey(key); d.setIv(iv); d.reset(); ByteArrayInputStream encIn = new ByteArrayInputStream(encrypted); ByteArrayOutputStream decOut = new ByteArrayOutputStream(); Encryption.decrypt(decOut, encIn, plaintext.length, d); byte[] result = decOut.toByteArray(); assertEquals("Decrypted result has different length than plaintext", result.length, plaintext.length); assertTrue("Transformation was not symmetric", Bytes.equals(result, plaintext)); }