@Override public Encryptor getEncryptor() { return new AESEncryptor(getJCECipherInstance(), rng); }
@Override public Decryptor getDecryptor() { return new AESDecryptor(getJCECipherInstance()); }
@Override public void reset() { init(); }
@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()); }
@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()); }
byte[] getHMAC(byte[] msg, int start, int len) throws SaslException { intToByte(mySeqNum); return calculateHMAC(myKey, seqNum, msg, start, len); }
@Override public Key getRandomKey() { byte[] keyBytes = new byte[getKeyLength()]; rng.nextBytes(keyBytes); return new SecretKeySpec(keyBytes, getName()); }
@Override public void reset() { init(); }
@Override public void write(byte[] buf, int off, int len) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("wrapping token of length:" + len); } // wrap with Crypto AES byte[] wrapped = cryptoAES.wrap(buf, off, len); DataOutputStream dob = new DataOutputStream(out); dob.writeInt(wrapped.length); dob.write(wrapped, 0, wrapped.length); dob.flush(); } }
@Override public Encryptor getEncryptor() { return new CommonsCryptoAESEncryptor(cipherMode, props, rng); }
@Override public Decryptor getDecryptor() { return new CommonsCryptoAESDecryptor(cipherMode, props); }
boolean comparePeerSeqNum(byte[] peerSeqNum) { return this.peerSeqNum == byteToInt(peerSeqNum); }
@Override public void reset() { if (iv == null) { iv = new byte[getIvLength()]; rng.nextBytes(iv); } initialized = true; } }
boolean compareHMAC(byte[] expectedHMAC, byte[] peerSeqNum, byte[] msg, int start, int len) throws SaslException { byte[] mac = calculateHMAC(peerKey, peerSeqNum, msg, start, len); return Arrays.equals(mac, expectedHMAC); }
@Override public Object run() { put("SecureRandom.TestRNG", TestAES.class.getName() + "$TestRNG"); return null; } });
@Override public Object run() { put("SecureRandom.TestRNG", TestCommonsAES.class.getName() + "$TestRNG"); return null; } });
@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 InputStream createDecryptionStream(InputStream in) { if (!initialized) { init(); } return new javax.crypto.CipherInputStream(in, cipher); }
@Override public OutputStream createEncryptionStream(OutputStream out) { if (!initialized) { init(); } return new javax.crypto.CipherOutputStream(out, cipher); }