code: public byte[] encrypt(byte[] iv, byte[] data) throws IntegrityException {
          if (data.length % blockSize != 0) {
              throw new IntegrityException("Incorrect data size");
          }
          if (iv.length != blockSize) {
              throw new IntegrityException("Incorrect iv size");
          }
  
          byte[] currentBlock = new byte[blockSize];
          byte[] res = new byte[data.length];
  
          byte[] currentIV = new byte[blockSize];
          for (int i = 0; i < blockSize; i++) {
              currentIV[i] = iv[i];
          }
  
          int count = data.length / blockSize;
          for (int i = 0; i < count; i++) {
  
              for (int j = 0; j < blockSize; j++) {
                  currentBlock[j] = (byte) ((data[i * blockSize + j] & 0xFF) ^ (currentIV[j] & 0xFF));
              }
  
              blockCipher.encryptBlock(currentBlock, 0, res, i * blockSize);
  
              for (int j = 0; j < blockSize; j++) {
                  currentIV[j] = res[i * blockSize + j];
              }
          }
  
          return res;
      }
docs: Encrypting data
  
  @param iv   initialization vector
  @param data data for encryption
  @return encrypted data