Esempio n. 1
0
        public static string ComputePassword(SecureString password, string salt)
        {
            var saltedPassword = password.Copy();

            foreach (var saltChar in salt)
            {
                saltedPassword.AppendChar(saltChar);
            }

            saltedPassword.MakeReadOnly();

            var passwordBytes = new byte[saltedPassword.Length * 2];
            var sha           = new SHA512Managed();
            var nativeString  = IntPtr.Zero;

            try
            {
                nativeString = Marshal.SecureStringToBSTR(saltedPassword);
                Marshal.Copy(nativeString, passwordBytes, 0, passwordBytes.Length);
            }
            finally
            {
                Marshal.ZeroFreeBSTR(nativeString);
            }

            byte[] hashedPassword = sha.ComputeHash(passwordBytes);
            sha.Clear();
            for (int i = 0; i < passwordBytes.Length; i++)
            {
                passwordBytes[i] = 0;
            }

            return(Convert.ToBase64String(hashedPassword));
        }
Esempio n. 2
0
        public static string FromString(string input, HashType hashtype)
        {
            Byte[] clearBytes;
            Byte[] hashedBytes;
            string output = String.Empty;

            switch (hashtype)
            {
            case HashType.RIPEMD160:
                clearBytes = new UTF8Encoding().GetBytes(input);
                RIPEMD160 myRIPEMD160 = RIPEMD160Managed.Create();
                hashedBytes = myRIPEMD160.ComputeHash(clearBytes);
                output      = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                break;

            case HashType.MD5:
                clearBytes  = new UTF8Encoding().GetBytes(input);
                hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
                output      = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                break;

            case HashType.SHA1:
                clearBytes = Encoding.UTF8.GetBytes(input);
                SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
                sha1.ComputeHash(clearBytes);
                hashedBytes = sha1.Hash;
                sha1.Clear();
                output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                break;

            case HashType.SHA256:
                clearBytes = Encoding.UTF8.GetBytes(input);
                SHA256 sha256 = new SHA256Managed();
                sha256.ComputeHash(clearBytes);
                hashedBytes = sha256.Hash;
                sha256.Clear();
                output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                break;

            case HashType.SHA384:
                clearBytes = Encoding.UTF8.GetBytes(input);
                SHA384 sha384 = new SHA384Managed();
                sha384.ComputeHash(clearBytes);
                hashedBytes = sha384.Hash;
                sha384.Clear();
                output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                break;

            case HashType.SHA512:
                clearBytes = Encoding.UTF8.GetBytes(input);
                SHA512 sha512 = new SHA512Managed();
                sha512.ComputeHash(clearBytes);
                hashedBytes = sha512.Hash;
                sha512.Clear();
                output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                break;
            }
            return(output);
        }
Esempio n. 3
0
        public static string SHA512Encrypt(string str)
        {
            SHA512 sha = new SHA512Managed();

            byte[] inArray = sha.ComputeHash(Encoding.Default.GetBytes(str));
            sha.Clear();
            return(Convert.ToBase64String(inArray));
        }
        public static string CreateSHAHash(string passwordSHA512)
        {
            SHA512Managed sha512 = new SHA512Managed();

            Byte[] EncryptedSHA512 = sha512.ComputeHash(Encoding.UTF8.GetBytes(string.Concat(passwordSHA512, SecurityCode)));
            sha512.Clear();
            return(Convert.ToBase64String(EncryptedSHA512));
        }
Esempio n. 5
0
        /// <summary>
        /// Sha512加密
        /// </summary>
        /// <param name="parameter">待加密参数</param>
        /// <param name="isReturnNum">是否返回为加密后字符的Byte代码</param>
        /// <returns></returns>
        public static string Sha512Encrypt(this string parameter, bool?isReturnNum = null)
        {
            SHA512 sha512  = new SHA512Managed();
            var    tmpByte = sha512.ComputeHash(GetKeyByteArray(parameter));

            sha512.Clear();
            return(GetStringValue(tmpByte, FindIsReturnNum(isReturnNum)));
        }
Esempio n. 6
0
 public static string CreateSHAHash(string Phrase)
 {
     SHA512Managed HashTool = new SHA512Managed();
     Byte[] PhraseAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(Phrase));
     Byte[] EncryptedBytes = HashTool.ComputeHash(PhraseAsByte);
     HashTool.Clear();
     return Convert.ToBase64String(EncryptedBytes);
 }
Esempio n. 7
0
        /// <summary>
        /// ½øÐÐSHA512¼ÓÃÜ
        /// </summary>
        /// <param name="strIn">Òª¼ÓÃܵÄ×Ö·û´®</param>
        /// <returns>¼ÓÃܺóµÄ×Ö·û´®</returns>
        public static string SHA512Encrypt(string strIn)
        {
            SHA512 sha512 = new SHA512Managed();

            byte[] tmpByte = sha512.ComputeHash(strIn.ToASCIIBytes());
            sha512.Clear();
            return(tmpByte.ToHexUpperString());
        }
Esempio n. 8
0
        public static string SHA512Encrypt(string strIN)
        {
            SHA512 sha = new SHA512Managed();

            byte[] @byte = sha.ComputeHash(GetKeyByteArray(strIN));
            sha.Clear();
            return(GetStringValue(@byte));
        }
Esempio n. 9
0
        public static string HashString(string phrase)
        {
            SHA512Managed HashTool = new SHA512Managed();

            Byte[] PasswordAsByte = Encoding.UTF8.GetBytes(string.Concat(phrase, SALT_PREFIX_SUFFIX_FORMAT));
            Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(EncryptedBytes));
        }
Esempio n. 10
0
        public static string SHA512Encrypt(string str, bool isReturnNum)
        {
            byte[] b      = GetKeyByteArray(str);
            SHA512 sha512 = new SHA512Managed();

            b = sha512.ComputeHash(b);
            sha512.Clear();
            return(GetStringValue(b, isReturnNum));
        }
Esempio n. 11
0
        /// <summary>
        /// SHA512加密,不可逆转
        /// </summary>
        /// <param name="str">string str:被加密的字符串</param>
        /// <returns>返回加密后的字符串</returns>
        public string Sha512Encrypt(string str)
        {
            SHA512 s512 = new SHA512Managed();

            byte[] bytes;
            bytes = s512.ComputeHash(Encoding.Default.GetBytes(str));
            s512.Clear();
            return(BitConverter.ToString(bytes).Replace("-", "").ToLower());
        }
Esempio n. 12
0
        private string GenSHA512Mp(string _inputMp)
        {
            SHA512Managed HashTool = new SHA512Managed();

            Byte[] HashAsByte = System.Text.Encoding.UTF8.GetBytes(_inputMp);
            Byte[] MpCrypted  = HashTool.ComputeHash(HashAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(MpCrypted));
        }
Esempio n. 13
0
        public static string Hash(string pPassword)
        {
            var hashTool       = new SHA512Managed();
            var phraseAsByte   = Encoding.UTF8.GetBytes(string.Concat(pPassword));
            var encryptedBytes = hashTool.ComputeHash(phraseAsByte);

            hashTool.Clear();
            return(Convert.ToBase64String(encryptedBytes));
        }
Esempio n. 14
0
        private string CreateSHAHash(string Password, string Salt)
        {
            SHA512Managed HashTool = new SHA512Managed();

            Byte[] PasswordAsByte = Encoding.UTF8.GetBytes(string.Concat(Password, Salt));
            Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(EncryptedBytes));
        }
Esempio n. 15
0
        /// <summary>
        /// SHA512加密,不可逆转
        /// </summary>
        /// <param name="str">string str:被加密的字符串</param>
        /// <returns>返回加密后的字符串</returns>
        public static string SHA512Encrypt(string str)
        {
            SHA512 s512 = new SHA512Managed();

            byte[] byte1;
            byte1 = s512.ComputeHash(Encoding.UTF8.GetBytes(str));
            s512.Clear();
            return(Convert.ToBase64String(byte1));
        }
Esempio n. 16
0
 /// <summary>
 /// SHA512加密,不可逆转
 /// </summary>
 /// <param name="encryptionString">被加密的字符串</param>
 /// <returns></returns>
 public static string SHA512_Encryption(string encryptionString)
 {
     using (SHA512 s512 = new SHA512Managed())
     {
         byte[] byte1 = s512.ComputeHash(Encoding.Default.GetBytes(encryptionString));
         s512.Clear();
         return(Convert.ToBase64String(byte1));
     }
 }
Esempio n. 17
0
        string EncryptSHA512(string token)
        {
            SHA512Managed HashTool = new SHA512Managed();

            Byte[] PhraseAsByte   = System.Text.Encoding.UTF8.GetBytes(string.Concat(token));
            Byte[] EncryptedBytes = HashTool.ComputeHash(PhraseAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(EncryptedBytes));
        }
Esempio n. 18
0
        public string PasswordHash(string password)
        {
            SHA512Managed HashTool = new SHA512Managed();

            Byte[] PhraseAsByte   = Encoding.UTF8.GetBytes(string.Concat(password));
            Byte[] EncryptedBytes = HashTool.ComputeHash(PhraseAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(EncryptedBytes));
        }
Esempio n. 19
0
        public static string GetHash(this string phrase)
        {
            SHA512Managed hashTool = new SHA512Managed();

            Byte[] phraseAsByte   = Encoding.UTF8.GetBytes(string.Concat(phrase));
            Byte[] encryptedBytes = hashTool.ComputeHash(phraseAsByte);
            hashTool.Clear();
            return(Convert.ToBase64String(encryptedBytes).SanitizeForFileName());
        }
Esempio n. 20
0
        /// <summary>
        /// 生成指定字符串的SHA512散列值(不可逆)
        /// </summary>
        /// <param name="srcValue">源字符串</param>
        /// <returns>SHA512值</returns>
        public static string Sha512Encode(string srcValue)
        {
            SHA512 sHa = new SHA512Managed();

            byte[] inArray = sHa.ComputeHash(Encoding.Default.GetBytes(srcValue));

            sHa.Clear();
            return(Convert.ToBase64String(inArray));
        }
Esempio n. 21
0
        public static string CreateSHAHash(string Phrase)
        {
            SHA512Managed HashTool = new SHA512Managed();

            Byte[] PhraseAsByte   = System.Text.Encoding.UTF8.GetBytes(string.Concat(Phrase));
            Byte[] EncryptedBytes = HashTool.ComputeHash(PhraseAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(EncryptedBytes));
        }
        public static string ToSHA512Hash(this string password, string saltKey = null)
        {
            SHA512Managed sha512 = new SHA512Managed();

            byte[] encryptedSHA512 = sha512.ComputeHash(Encoding.UTF8.GetBytes(string.Concat(password, saltKey)));
            sha512.Clear();

            return(Convert.ToBase64String(encryptedSHA512));
        }
Esempio n. 23
0
        public string SHA512Encrypt(string strIN)
        {
            byte[] tmpByte;
            SHA512 sha512 = new SHA512Managed();

            tmpByte = sha512.ComputeHash(GetKeyByteArray(strIN));
            sha512.Clear();
            return(GetStringValue(tmpByte));
        }
Esempio n. 24
0
        /// <summary>
        /// SHA1Managed 哈希算法-512 位
        /// huhm2008
        /// </summary>
        /// <param name="plainText">原字符串</param>
        /// <returns>加密后字符串</returns>
        public static string SHA512Encrypt(string plainText)
        {
            byte[] tmpByte;
            SHA512 sha512 = new SHA512Managed();

            tmpByte = sha512.ComputeHash(GetKeyByteArray(plainText));
            sha512.Clear();

            return(GetStringValue(tmpByte, true));
        }
Esempio n. 25
0
        private string PasswordEncrypt(string password)
        {
            SHA512Managed HashTool = new SHA512Managed();

            Byte[] PhraseAsByte      = System.Text.Encoding.UTF8.GetBytes(string.Concat(password));
            Byte[] EncryptedPassword = HashTool.ComputeHash(PhraseAsByte);
            HashTool.Clear();

            return(Convert.ToBase64String(EncryptedPassword));
        }
Esempio n. 26
0
        private string Sha512Hash(string rawString)
        {
            var rawStringBytes = Encoding.Unicode.GetBytes(rawString);
            var hashProvider   = new SHA512Managed();

            hashProvider.Initialize();
            rawStringBytes = hashProvider.ComputeHash(rawStringBytes);
            hashProvider.Clear();
            return(Convert.ToBase64String(rawStringBytes));
        }
Esempio n. 27
0
        private static string ComputeSHAHash(string data)
        {
            SHA512Managed sha512 = new SHA512Managed();

            Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(data));
            sha512.Clear();
            string hashed = BitConverter.ToString(EncryptedSHA512).Replace("-", "").ToLower();

            return(hashed);
        }
Esempio n. 28
0
 public static string CreateShaHash(string password)
 {
     using (var hashTool = new SHA512Managed())
     {
         byte[] passwordAsByte = Encoding.ASCII.GetBytes(password);
         byte[] encryptedBytes = hashTool.ComputeHash(passwordAsByte);
         hashTool.Clear();
         return(BitConverter.ToString(encryptedBytes).Replace("-", "").ToLowerInvariant());
     }
 }
Esempio n. 29
0
        /// <summary>
        ///     计算输入数据的 SHA512 哈希值
        /// </summary>
        /// <param name="strIn">输入的数据.</param>
        /// <returns></returns>
        public static string Sha512Encrypt(string strIn)
        {
            //string strIN = getstrIN(strIN);
            SHA512 sha512 = new SHA512Managed();

            byte[] tmpByte = sha512.ComputeHash(StringToBytes(strIn));
            sha512.Clear();

            return(BytesToString(tmpByte));
        }
Esempio n. 30
0
 public static string SHA512(string sourceText)
 {
     using (var sha512 = new SHA512Managed())
     {
         var tmpByte = Encoding.UTF8.GetBytes(sourceText);
         var bytes   = sha512.ComputeHash(tmpByte);
         sha512.Clear();
         return(BitConverter.ToString(bytes).Replace("-", "").ToLower());
     }
 }
Esempio n. 31
0
        public string geraHash(string senha)
        {
            string        _senha = "";
            SHA512Managed hash   = new SHA512Managed();

            byte[] senhaByte = Encoding.UTF8.GetBytes(senha);
            byte[] hashByte  = hash.ComputeHash(senhaByte);
            hash.Clear();
            _senha = Convert.ToBase64String(hashByte);
            return(_senha);
        }
Esempio n. 32
0
    //AIM: THIS FUNCTION IS USE to encrypt the string and create hask key using diff hash methods
    public string FromString(string input, HashType hashtype)
    {
        Byte[] clearBytes;
            Byte[] hashedBytes;
            string output = String.Empty;

            switch (hashtype)
            {
                case HashType.RIPEMD160:
                    clearBytes = new UTF8Encoding().GetBytes(input);
                    RIPEMD160 myRIPEMD160 = RIPEMD160Managed.Create();
                    hashedBytes = myRIPEMD160.ComputeHash(clearBytes);
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.MD5:
                    clearBytes = new UTF8Encoding().GetBytes(input);
                    hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA1:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
                    sha1.ComputeHash(clearBytes);
                    hashedBytes = sha1.Hash;
                    sha1.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA256:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA256 sha256 = new SHA256Managed();
                    sha256.ComputeHash(clearBytes);
                    hashedBytes =sha256.Hash;

                    sha256.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA384:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA384 sha384 = new SHA384Managed();
                    sha384.ComputeHash(clearBytes);
                    hashedBytes = sha384.Hash;
                    sha384.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA512:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA512 sha512 = new SHA512Managed();
                    sha512.ComputeHash(clearBytes);
                    hashedBytes = sha512.Hash;
                    sha512.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
            }
            return output;
    }