Esempio n. 1
0
        public string GenerateToken()
        {
            var randomBytes = new byte[32];
            var prng        = new RNGCryptoServiceProvider();

            prng.GetBytes(randomBytes);

            return(EncodingUtil.Base64Encode(randomBytes));
        }
Esempio n. 2
0
        public string Pbkdf2(string value, string salt, int iterations)
        {
            var hash = EncodingUtil.HexEncode(PBKDF2Sha256GetBytes(
                                                  32,
                                                  Encoding.UTF8.GetBytes(value),
                                                  Encoding.UTF8.GetBytes(salt),
                                                  iterations));

            return(hash);
        }
Esempio n. 3
0
        public string CreateSignature(string key, string data)
        {
            var keyBytes = Encoding.UTF8.GetBytes(key);

            byte[] hashValue;
            using (var hmac = new HMACSHA256(keyBytes))
            {
                hashValue = hmac.ComputeHash(Encoding.UTF8.GetBytes(data));
            }
            return(EncodingUtil.HexEncode(hashValue));
        }