code: static void decrementKey(byte[] key)
    {
      for (int i = key.length - 1; i >= 0; i--) {
        int v = key[i] & 0xff;
        
        if (v > 0) {
          key[i] = (byte) (v - 1);
          return;
        }
        
        key[i] = (byte) 0xff;
      }
    }
docs: Decrement a key.