A Go library for obfuscating integer IDs using Knuth's hashing algorithm to hide database primary keys.
Optimus-go is a Go library that provides reversible integer ID obfuscation using Knuth's hashing algorithm. It transforms internal database IDs into non-sequential numbers to prevent exposing sensitive primary keys in URLs or APIs, while allowing perfect reconstruction of the original IDs.
Go developers building web services or APIs who need to hide sequential database primary keys from public exposure, such as in URLs or API responses.
Developers choose Optimus-go for its speed, simplicity, and security, as it implements Knuth's algorithm which is 127 times faster than alternatives like hashids in benchmarks, produces integer-only output to avoid encoding issues, and has no external dependencies.
ID hashing and Obfuscation using Knuth's Algorithm
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Benchmarks show it's 127 times faster than hashids, making it ideal for high-throughput Go services where speed is critical.
Uses Knuth's algorithm to encode and decode IDs without loss, ensuring accurate reconstruction of original values for reliable data mapping.
Produces obfuscated IDs as pure integers, avoiding string encoding issues like leading zeros that can disrupt decoding, as noted in comparisons with hashids.
Includes generator.GenerateSeed() to easily create the required prime, mod inverse, and random number, simplifying secure setup without manual calculations.
IDs must be less than 2147483647 (MAXID), restricting use for modern databases with 64-bit keys and limiting scalability for larger systems.
Requires secure generation, storage, and consistency of three numbers (prime, mod inverse, random), adding operational overhead and risk if compromised.
The New function panics on invalid primes, which can lead to application crashes without external error handling, as warned in the README.