public void init(Map attributes)
   throws InvalidKeyException, IllegalStateException {
      synchronized(lock) {
         if (state != -1) {
            throw new IllegalStateException();
         }

         Integer want = (Integer) attributes.get(STATE);
         if (want != null) {
            switch (want.intValue()) {
            case ENCRYPTION: state = ENCRYPTION; break;
            case DECRYPTION: state = DECRYPTION; break;
            default: throw new IllegalArgumentException();
            }
         }

         Integer bs = (Integer) attributes.get(MODE_BLOCK_SIZE);
         modeBlockSize = (bs == null ? cipherBlockSize : bs.intValue());

         byte[] iv = (byte[]) attributes.get(IV);
         if (iv != null) {
            this.iv = (byte[]) iv.clone();
         } else {
            this.iv = new byte[modeBlockSize];
         }

         cipher.init(attributes);
         setup();
      }
   }