private string GetHash(string url) { Base62Converter base62 = new Base62Converter(); string hash = base62.Encode(GetMd5Hash(url)); return(hash.Substring(0, 6)); }
public void Test() { var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var encoded = Base62Converter.Encode(data); var decoded = Base62Converter.Decode(encoded); Assert.Equal(data, decoded); }
public void ASCII_AND_UTF8_Can_RoundTrip(string input, string expected) { var converter = new Base62Converter(Base62Converter.CharacterSet.DEFAULT); var encoded = converter.Encode(input); var decoded = converter.Decode(encoded); Assert.AreEqual(expected, encoded); Assert.AreEqual(input, decoded); }
public void NonAscii_CanBe_Decoded() { var input = "love爱"; var converter = new Base62Converter(Base62Converter.CharacterSet.DEFAULT); var encoded = converter.Encode(input); var decoded = converter.Decode(encoded); Assert.AreEqual(input, decoded); }
public void Encoded_Inverted_CanBe_Decoded() { var input = "Whatup"; var converter = new Base62Converter(Base62Converter.CharacterSet.INVERTED); var encoded = converter.Encode(input); var decoded = converter.Decode(encoded); Assert.AreEqual(input, decoded); }
public void Encoded_CanBe_Decoded() { var input = "120"; var converter = new Base62Converter(); var encoded = converter.Encode(input); var decoded = converter.Decode(encoded); Assert.AreEqual(input, decoded); }
public void TestEquality() { var bytes = new byte[ByteLength]; random.GetBytes(bytes); var s = Base62Converter.Encode(bytes); var decode = Base62Converter.Decode(s.ToCharArray()); var encode = Base62Converter.Encode(decode); Assert.AreEqual(s, encode); }
/// <summary> /// Create an acknowledge message. /// </summary> /// <param name="timeout">The response timeout.</param> public AcknowledgeRequest(string token = null) { if (token != null) { AckToken = token; } else { byte[] buffer = new byte[2]; _rand.NextBytes(buffer); AckToken = _tokenGenerator.Encode( BitConverter.ToString(buffer).Replace("-", string.Empty) ); } }
/// <summary> /// Creates the URL. /// </summary> /// <param name="createUrlRequest">The create URL request.</param> /// <returns></returns> public async Task <CreateUrlResponse> CreateUrl(CreateUrlRequest createUrlRequest) { Ensure.NotNullOrEmpty(createUrlRequest.Url, "url params can't be null"); Base62Converter converter = new Base62Converter(); long id = await this.keyValueStore.GetNewId(); string segment = converter.Encode(id.ToString()); string host = GetHost(); CreateUrlResponse createUrlResponse = CreateUrlResponse .Create(segment, $"{host}/{segment}", createUrlRequest.Url); await this.keyValueStore.Add(segment, createUrlResponse); return(createUrlResponse); }
public static string ToBase62(this int number) { var converter = new Base62Converter(); return(converter.Encode(number.ToString())); }
public static string Base62Encode(string plainText) { return(_base62Converter.Encode(plainText)); }
public static readonly Random Rnd = new Random(); //default /// <summary> /// Guid in base64 format /// </summary> /// <returns></returns> public static string NewGuid() { // return Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Replace("=", ""), "[/]", "-"); return(B62.Encode(Guid.NewGuid().ToByteArray())); }