I am using Hashids to hide database IDs in the URL. Following is my initialization of Hashids:
public static Security.Hashids HashOps = new Security.Hashids("Sl212", 5);
Security
is my project's namespace inside which I copied Hashids.cs file. The encoding is working correctly but decoding is throwing IndexOutOfRangeException
exception. This is how I am decoding:
int fileID=HashOps.Decode(FileID)[0];
I tried it on many salts and without salt, but its throwing the same exception again and again. I am using the original code from the file. Except namespace I changed nothing.
Please tell me what to do? After trying for 12 hours my mind is stuck at dead end.
UPDATE
A test code I am running in Console app also throwing exception:
Hashids HashOps = new Hashids();
string hash = HashOps.Encode(212);
Console.WriteLine("Encoded: " + hash);
Console.WriteLine("Decoded: " + HashOps.Decode(hash)[0]);
Finally, with the help of @Heinzi I was able to detect what was really going on. The problem was with my web application's URL detection system. Which detects the URL and loads the content in a DIV. That system was making the complete URL lower cased. Hence, changing the hash containing the capital letter. I just used the actual URL instead of lowered one when detecting IDs.