Beispiel #1
0
        /// <summary>
        /// Used for creating small readable crypto-tokens
        /// </summary>
        /// <param name="minimumLength"></param>
        /// <param name="tokenHashAlphabet"></param>
        /// <returns></returns>
        public static string CreateEncodedHashId(int minimumLength, string tokenHashAlphabet)
        {
            var seed = new Random(BitConverter.ToInt32(CreateRandomBytes(4), 0)).Next(0, int.MaxValue);
            var salt = CreateRandomBytes(32);

            string saltString = Convert.ToBase64String(salt);

            var hashId = new HashidsNet.Hashids(salt: saltString, minHashLength: minimumLength, alphabet: tokenHashAlphabet);
            var hash   = hashId.Encode(seed);

            return(hash);
        }
Beispiel #2
0
 public string Encrypt(int id)
 {
     return(_hash.Encode(id));
 }
Beispiel #3
0
 public void RoundtripInts()
 {
     var encodedValue = _hashids.Encode(_ints);
     var decodedValue = _hashids.Decode(encodedValue);
 }
Beispiel #4
0
 public string GenerateHash(int urlId)
 {
     return(_hashIds.Encode(urlId));
 }