@Override public Cipher getCipher(String name) { if (name.equalsIgnoreCase("AES")) { return new CommonsCryptoAES(this); } throw new RuntimeException("Cipher '" + name + "' is not supported by provider '" + getName() + "'"); }
@Override public Key getRandomKey() { byte[] keyBytes = new byte[getKeyLength()]; rng.nextBytes(keyBytes); return new SecretKeySpec(keyBytes, getName()); }
public CommonsCryptoAES(CipherProvider provider) { super(provider); // The mode for Commons Crypto Ciphers cipherMode = provider.getConf().get(CIPHER_MODE_KEY, "AES/CTR/NoPadding"); // Reads Commons Crypto properties from HBase conf props = readCryptoProps(provider.getConf()); // RNG algorithm rngAlgorithm = provider.getConf().get(RNG_ALGORITHM_KEY, "SHA1PRNG"); // RNG provider, null if default String rngProvider = provider.getConf().get(RNG_PROVIDER_KEY); try { if (rngProvider != null) { rng = SecureRandom.getInstance(rngAlgorithm, rngProvider); } else { rng = SecureRandom.getInstance(rngAlgorithm); } } catch (GeneralSecurityException e) { LOG.warn("Could not instantiate specified RNG, falling back to default", e); rng = new SecureRandom(); } }
@Override public InputStream createDecryptionStream(InputStream in, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Decryptor d = getDecryptor(); d.setKey(context.getKey()); d.setIv(iv); return d.createDecryptionStream(in); }
@Override public OutputStream createEncryptionStream(OutputStream out, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Encryptor e = getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); return e.createEncryptionStream(out); }
@Override public InputStream createDecryptionStream(InputStream in, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Decryptor d = getDecryptor(); d.setKey(context.getKey()); d.setIv(iv); return d.createDecryptionStream(in); }
@Override public OutputStream createEncryptionStream(OutputStream out, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Encryptor e = getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); return e.createEncryptionStream(out); }
@Override public Key getRandomKey() { byte[] keyBytes = new byte[getKeyLength()]; rng.nextBytes(keyBytes); return new SecretKeySpec(keyBytes, getName()); }
@Override public InputStream createDecryptionStream(InputStream in, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Decryptor d = getDecryptor(); d.setKey(context.getKey()); d.setIv(iv); return d.createDecryptionStream(in); }
@Override public Cipher getCipher(String name) { if (name.equalsIgnoreCase("AES")) { return new CommonsCryptoAES(this); } throw new RuntimeException("Cipher '" + name + "' is not supported by provider '" + getName() + "'"); }
@Override public OutputStream createEncryptionStream(OutputStream out, Context context, byte[] iv) throws IOException { Preconditions.checkNotNull(context); Preconditions.checkState(context.getKey() != null, "Context does not have a key"); Preconditions.checkNotNull(iv); Encryptor e = getEncryptor(); e.setKey(context.getKey()); e.setIv(iv); return e.createEncryptionStream(out); }
public CommonsCryptoAES(CipherProvider provider) { super(provider); // The mode for Commons Crypto Ciphers cipherMode = provider.getConf().get(CIPHER_MODE_KEY, "AES/CTR/NoPadding"); // Reads Commons Crypto properties from HBase conf props = readCryptoProps(provider.getConf()); // RNG algorithm rngAlgorithm = provider.getConf().get(RNG_ALGORITHM_KEY, "SHA1PRNG"); // RNG provider, null if default String rngProvider = provider.getConf().get(RNG_PROVIDER_KEY); try { if (rngProvider != null) { rng = SecureRandom.getInstance(rngAlgorithm, rngProvider); } else { rng = SecureRandom.getInstance(rngAlgorithm); } } catch (GeneralSecurityException e) { LOG.warn("Could not instantiate specified RNG, falling back to default", e); rng = new SecureRandom(); } }
@Override public Key getRandomKey() { byte[] keyBytes = new byte[getKeyLength()]; rng.nextBytes(keyBytes); return new SecretKeySpec(keyBytes, getName()); }
@Override public Cipher getCipher(String name) { if (name.equalsIgnoreCase("AES")) { return new CommonsCryptoAES(this); } throw new RuntimeException("Cipher '" + name + "' is not supported by provider '" + getName() + "'"); }
public CommonsCryptoAES(CipherProvider provider) { super(provider); // The mode for Commons Crypto Ciphers cipherMode = provider.getConf().get(CIPHER_MODE_KEY, "AES/CTR/NoPadding"); // Reads Commons Crypto properties from HBase conf props = readCryptoProps(provider.getConf()); // RNG algorithm rngAlgorithm = provider.getConf().get(RNG_ALGORITHM_KEY, "SHA1PRNG"); // RNG provider, null if default String rngProvider = provider.getConf().get(RNG_PROVIDER_KEY); try { if (rngProvider != null) { rng = SecureRandom.getInstance(rngAlgorithm, rngProvider); } else { rng = SecureRandom.getInstance(rngAlgorithm); } } catch (GeneralSecurityException e) { LOG.warn("Could not instantiate specified RNG, falling back to default", e); rng = new SecureRandom(); } }