@Test public void testAlternateRNG() throws Exception { Security.addProvider(new TestProvider()); Configuration conf = new Configuration(); conf.set(AES.RNG_ALGORITHM_KEY, "TestRNG"); conf.set(AES.RNG_PROVIDER_KEY, "TEST"); DefaultCipherProvider.getInstance().setConf(conf); AES aes = new AES(DefaultCipherProvider.getInstance()); assertEquals("AES did not find alternate RNG", "TestRNG", aes.getRNG().getAlgorithm()); }
@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 Cipher getCipher(String name) { if (name.equalsIgnoreCase("AES")) { return new AES(this); } throw new RuntimeException("Cipher '" + name + "' is not supported by provider '" + getName() + "'"); }
@Override public Encryptor getEncryptor() { return new AESEncryptor(getJCECipherInstance(), rng); }
@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 AES(this); } throw new RuntimeException("Cipher '" + name + "' is not supported by provider '" + getName() + "'"); }
@Override public Decryptor getDecryptor() { return new AESDecryptor(getJCECipherInstance()); }
@Test public void testAlternateRNG() throws Exception { Security.addProvider(new TestProvider()); Configuration conf = new Configuration(); conf.set(AES.RNG_ALGORITHM_KEY, "TestRNG"); conf.set(AES.RNG_PROVIDER_KEY, "TEST"); DefaultCipherProvider.getInstance().setConf(conf); AES aes = new AES(DefaultCipherProvider.getInstance()); assertEquals("AES did not find alternate RNG", "TestRNG", aes.getRNG().getAlgorithm()); }
@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 AES(this); } throw new RuntimeException("Cipher '" + name + "' is not supported by provider '" + getName() + "'"); }
@Override public Decryptor getDecryptor() { return new AESDecryptor(getJCECipherInstance()); }
@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); }
@Test public void testAlternateRNG() throws Exception { Security.addProvider(new TestProvider()); Configuration conf = new Configuration(); conf.set(AES.RNG_ALGORITHM_KEY, "TestRNG"); conf.set(AES.RNG_PROVIDER_KEY, "TEST"); DefaultCipherProvider.getInstance().setConf(conf); AES aes = new AES(DefaultCipherProvider.getInstance()); assertEquals("AES did not find alternate RNG", "TestRNG", aes.getRNG().getAlgorithm()); }
@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 AES(this); } throw new RuntimeException("Cipher '" + name + "' is not supported by provider '" + getName() + "'"); }
@Override public Encryptor getEncryptor() { return new AESEncryptor(getJCECipherInstance(), rng); }
@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); }