Exemple #1
0
        public GenericHashResult ComputeHash(string stringToComputeHash, string salt, bool enhancedEntropy, BCryptNet.HashType hashType = BCryptNet.HashType.SHA384)
        {
            if (string.IsNullOrWhiteSpace(stringToComputeHash))
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = MessageDictionary.Instance["Hash.InputRequired"]
                });
            }

            try
            {
                var hashedString = BCryptNet.BCrypt.HashPassword(stringToComputeHash, salt, enhancedEntropy, hashType);

                return(new GenericHashResult()
                {
                    Success = true,
                    Message = MessageDictionary.Instance["Hash.ComputeSuccess"],
                    HashString = hashedString
                });
            }
            catch (Exception ex)
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = ex.ToString()
                });
            }
        }
        public GenericHashResult HashString(string stringToBeHashed, string salt, bool enhancedEntropy, BCryptNet.HashType hashType = BCryptNet.HashType.SHA384)
        {
            if (string.IsNullOrWhiteSpace(stringToBeHashed))
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = "String to be hashed required."
                });
            }

            try
            {
                var hashedString = BCryptNet.BCrypt.HashPassword(stringToBeHashed, salt, enhancedEntropy, hashType);

                return(new GenericHashResult()
                {
                    Success = true,
                    Message = "String succesfully hashed.",
                    Hash = hashedString
                });
            }
            catch (Exception ex)
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = ex.ToString()
                });
            }
        }
Exemple #3
0
        public GenericHashResult VerifyHash(string stringToComputeHash, string hash, bool enhancedEntropy = false, BCryptNet.HashType hashType = BCryptNet.HashType.SHA384)
        {
            if (string.IsNullOrWhiteSpace(stringToComputeHash))
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = MessageDictionary.Instance["Hash.InputRequired"]
                });
            }

            if (string.IsNullOrWhiteSpace(hash))
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = MessageDictionary.Instance["Hash.VerificationHashRequired"]
                });
            }

            try
            {
                var match = BCryptNet.BCrypt.Verify(stringToComputeHash, hash, enhancedEntropy, hashType);

                if (match)
                {
                    return(new GenericHashResult()
                    {
                        Success = true,
                        Message = MessageDictionary.Instance["Hash.Match"],
                        HashString = hash
                    });
                }
                else
                {
                    return(new GenericHashResult()
                    {
                        Success = false,
                        Message = MessageDictionary.Instance["Hash.DoesNotMatch"]
                    });
                }
            }
            catch (Exception ex)
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = ex.ToString()
                });
            }
        }
        public GenericHashResult Verify(string stringToBeVerified, string hashedString, bool enhancedEntropy = false, BCryptNet.HashType hashType = BCryptNet.HashType.SHA384)
        {
            if (string.IsNullOrWhiteSpace(stringToBeVerified))
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = "String to be verified required."
                });
            }

            try
            {
                var match = BCryptNet.BCrypt.Verify(stringToBeVerified, hashedString, enhancedEntropy, hashType);

                if (match)
                {
                    return(new GenericHashResult()
                    {
                        Success = true,
                        Message = "String and hash match.",
                        Hash = hashedString
                    });
                }
                else
                {
                    return(new GenericHashResult()
                    {
                        Success = false,
                        Message = "String and hash does not match."
                    });
                }
            }
            catch (Exception ex)
            {
                return(new GenericHashResult()
                {
                    Success = false,
                    Message = ex.ToString()
                });
            }
        }