在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):leprosus/kotlin-hashids开源软件地址(OpenSource Url):https://github.com/leprosus/kotlin-hashids开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Hashids.ktA Kotlin class to generate YouTube-like hashes from one or many numbers. Ported from Java Hashids.java by fanweixiao (is port of javascript hashids.js by Ivan Akimov) What is it?Hashids (Hash ID's) creates short, unique, decryptable hashes from unsigned (long) integers. This algorithm tries to satisfy the following requirements:
Instead of showing items as All (long) integers need to be greater than or equal to zero. UsageImport the packageimport org.hashids; Encrypting one numberYou must pass a unique salt string so your hashes differ from everyone. I use "this is my salt" as an example. val hashids = Hashids("this is my salt")
val hash: String = hashids.encode(12345)
DecryptingNotice: during decryption, the same salt value has to be used: val hashids = Hashids("this is my salt")
val numbers: LongArray = hashids.decode("NkK9")
val numver: Int = numbers[0]
Decrypting with different saltDecryption will not work if salt is changed: val hashids = Hashids("this is my pepper")
val numbers: LongArray = hashids.decode("NkK9")
Encrypting several numbersval hashids = Hashids("this is my salt")
val hash: String = hashids.encode(683L, 94108L, 123L, 5L)
Decrypting is done the same wayval hashids = Hashids("this is my salt")
val numbers: String = hashids.decode("aBMswoO2UB3Sj")
Encrypting and specifying minimum hash lengthHere we encode integer 1, and set the minimum hash length to 8 (by default it's 0 -- meaning hashes will be the shortest possible length). val hashids = Hashids("this is my salt", 8)
val hash: String = hashids.encode(1)
Decryptingval hashids = Hashids("this is my salt", 8)
val numbers: String = hashids.decode("gB0NV05e")
Specifying custom hash alphabetLet's set the alphabet that consist of only four letters: "0123456789abcdef" val hashids = Hashids("this is my salt", 0, "0123456789abcdef")
val hash: String = hashids.encode(1234567)
Repeating numbersval hashids = Hashids("this is my salt")
val hash: String = hashids.encode(5, 5, 5, 5); You don't see any repeating patterns that might show there's 4 identical numbers in the hash: 1Wc8cwcE Same with incremented numbers: val hashids = Hashids("this is my salt")
val hash: String = hashids.encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
Incrementing number hashes:val hashids = Hashids("this is my salt")
val hash1: String = hashids.encode(1) /* NV */
val hash2: String = hashids.encode(2) /* 6m */
val hash3: String = hashids.encode(3) /* yD */
val hash4: String = hashids.encode(4) /* 2l */
val hash5: String = hashids.encode(5) /* rD */ ContactFollow me @leprosus, @IvanAkimov, @fanweixiao, @spuklo LicenseMIT License. See the |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论