Hi, I just registered because I found this code through some google search and I wanted to see if this code works.
I had the same issue with the IndexOutOfBounds Exception.
I changed this line
sb = sb + ValidChars[index]
to
sb = sb + ValidChars[index % 32]
and got rid of the exception and I tested a generated key and it worked.
I have no clue what this program does but I thought might aswell share it