Пример #1
0
        public string DeriveSha256Key(string password)
        {
            int iterations   = 1;   // The number of times to encrypt the password
            int saltByteSize = 8;   // the salt size
            int hashByteSize = 256; // the final hash

            var hash = new ShaHash();

            byte[] saltBytes  = hash.CreateSalt(saltByteSize);
            string saltString = Convert.ToBase64String(saltBytes);
            string key        = hash.Pbkdf2Sha256GetHash(password, saltString, iterations, hashByteSize);

            //var isValid = hash.ValidatePassword(password, saltBytes, iterations, hashByteSize, Convert.FromBase64String(key));
            return(key);
        }
Пример #2
0
        public ShaResult DeriveShaKey(string password, int keySize, byte[] saltBytes)
        {
            int iterations   = 1;       // The number of times to encrypt the password
            int hashByteSize = keySize; // the final hash

            var hash = new ShaHash();

            string saltString = Convert.ToBase64String(saltBytes);
            string key        = hash.Pbkdf2Sha256GetHash(password, saltString, iterations, hashByteSize);

            //var isValid = hash.ValidatePassword(password, saltBytes, iterations, hashByteSize, Convert.FromBase64String(key));
            return(new ShaResult {
                Digest = key, Salt = saltBytes
            });
        }