- Hashid is initialized with an
minimum hash length
- It's possible to hash single and multiple long numbers
- Hashes are unique across the salt value
- Hashes are decryptable to a single or multiple numbers respectively
- Hashes don't contain English curse words
- Supports positive long numbers
- The primary purpose of hashids is to obfuscate ids
- Do not use hashids for security purposes or compression
The goal of the port
Besides the goals of the original library, this scala port is written without mutable state. Also you get clear exceptions in following cases:
IllegalArgumentExceptionwhen alphabet, you provided, contains duplicates
IllegalArgumentExceptionif alphabet contains spaces
IllegalArgumentExceptionif alphabet is less then 16 chars long
encodeHexwith non-HEX string
decodewith hash, produced with different salt
Cross-Built for Scala 2.11, 2.12 and 2.13
libraryDependencies += "com.github.ancane" %% "hashids-scala" % "1.4"
import org.hashids.Hashids, Hashids._
You should provide your own unique salt to get hashes, different from other hashids. Do not use salf from the examples.
val hashids = Hashids("this is my salt") val hash = hashids.encode(12345L) > "NkK9"
During decryption, same salt must be used to get original numbers back:
val hashids = Hashids("this is my salt") val numbers = hashids.decode("NkK9") > List(12345L): Seq[Long]
MIT License. See the