Example #1
0
        private string GetHash(string url)
        {
            Base62Converter base62 = new Base62Converter();
            string          hash   = base62.Encode(GetMd5Hash(url));

            return(hash.Substring(0, 6));
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        /// <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)
                    );
            }
        }
Example #9
0
        /// <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);
        }
Example #10
0
        public static string ToBase62(this int number)
        {
            var converter = new Base62Converter();

            return(converter.Encode(number.ToString()));
        }
Example #11
0
 public static string Base62Encode(string plainText)
 {
     return(_base62Converter.Encode(plainText));
 }
Example #12
0
File: F.cs Project: jimliuxyz/UW
        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()));
        }