@Override public void initialize(Direction direction, SymmetricKey key) { this.key = key.getKey(); if (initialized()) { CipherParameters params = new KeyParameter(this.key); aesEngine.init(direction == Direction.ENCRYPT, params); } }
/** * Encrypt/decrypt source block and return processed block * * @param block source block * @return transformed source block * @throws EncryptionError if key or block has wrong size */ @Override public byte[] transformBlock(byte[] block) throws EncryptionError { if (!initialized()) { throw new EncryptionError("Not initialized with proper key"); } else { byte[] buf = new byte[getBlockSize()]; aesEngine.processBlock(block, 0, buf, 0); return buf; } } }