コード例 #1
0
ファイル: HashEncode.cs プロジェクト: jimlly/SMSProject
        /// <summary>
        /// 哈希加密一个字符串
        /// </summary>
        /// <param name="Security"></param>
        /// <returns></returns>
        public static string HashEncoding(string Security)
        {
            byte[] Value;
            SHA512Managed Arithmetic = null;
            try
            {
                UnicodeEncoding Code = new UnicodeEncoding();
                byte[] Message = Code.GetBytes(Security);

                Arithmetic = new SHA512Managed();
                Value = Arithmetic.ComputeHash(Message);
                Security = "";
                foreach (byte o in Value)
                {
                    Security += (int)o + "O";
                }

                return Security;
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                if (Arithmetic!=null)
                {
                    Arithmetic.Clear();
                }
            }
        }
コード例 #2
0
 public string getSha512(string Password)
 {
     System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(Password);
     Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
     HashTool.Clear();
     return(Convert.ToBase64String(EncryptedBytes));
 }
コード例 #3
0
ファイル: CryptoHelper.cs プロジェクト: laisee/API-V1-DotNet
 public static string CreateSHA2512Hash(string phrase)
 {
     var HashTool = new SHA512Managed();
     Byte[] PasswordAsByte = Encoding.UTF8.GetBytes(phrase);
     Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
     HashTool.Clear();
     return Convert.ToBase64String(EncryptedBytes);
 }
コード例 #4
0
ファイル: EncryptHelper.cs プロジェクト: LikesSa/xsy2.0
 /// <summary>
 /// SHA512加密,不可逆转
 /// </summary>
 /// <param name="str">string str:被加密的字符串</param>
 /// <returns>返回加密后的字符串</returns>
 public static string SHA512Encrypt(string str)
 {
     System.Security.Cryptography.SHA512 s512 = new System.Security.Cryptography.SHA512Managed();
     byte[] byte1;
     byte1 = s512.ComputeHash(Encoding.Default.GetBytes(str));
     s512.Clear();
     return(Convert.ToBase64String(byte1));
 }
コード例 #5
0
ファイル: CryptoHelper.cs プロジェクト: slycoderr/greenhand
 internal static string CreateSHAHash(string password, string salt)
 {
     System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(password, salt));
     Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
     HashTool.Clear();
     return(Convert.ToBase64String(EncryptedBytes));
 }
コード例 #6
0
 public static string CreateSHAHash(string Password, string Salt)
 {
     System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(Password, Salt));
     Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
     HashTool.Clear();
     return Convert.ToBase64String(EncryptedBytes);
 }
コード例 #7
0
 public static byte[] 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 EncryptedBytes;
 }
コード例 #8
0
ファイル: Cryptography.cs プロジェクト: nhanthieugia/BSG
 /// <summary>
 /// Create SHA2 hash
 /// </summary>
 /// <param name="phrase"></param>
 /// <returns></returns>
 public static string CreateShaHash(string[] phrase)
 {
     var hashTool = new SHA512Managed();
     var phraseAsByte = Encoding.UTF8.GetBytes(string.Concat(phrase));
     var encryptedBytes = hashTool.ComputeHash(phraseAsByte);
     hashTool.Clear();
     return BitConverter.ToString(encryptedBytes);
 }
コード例 #9
0
 /// <summary>
 /// Genera el hash de la familia SHA2, SHA512 de la password en todo proceso de registro o logeo. El parámetro salt se suele dejar vacio, pues no se usa sal en esta aplicación.
 /// </summary>
 /// <param name="password"></param>
 /// <param name="salt"></param>
 /// <returns></returns>
 public static string GetSHA512(string password, string salt)
 {
     System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(password, salt));
     Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
     HashTool.Clear();
     return BitConverter.ToString(EncryptedBytes);
 }
コード例 #10
0
 /// <summary>
 /// SHA512加密
 /// </summary>
 /// <param name="insertStr"></param>
 /// <returns></returns>
 public static string SHA512Encrypt(string insertStr)
 {
     byte[] tmpByte;
     SHA512 sha512 = new SHA512Managed();
     tmpByte = sha512.ComputeHash(GetKeyByteArray(insertStr));
     sha512.Clear();
     return GetStringValue(tmpByte);
 }
コード例 #11
0
        public static string GTBSHA512(string hash_string)
        {
            System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
            Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hash_string));
            sha512.Clear();
            string hashed = BitConverter.ToString(EncryptedSHA512).Replace("-", "").ToLower();

            return(hashed);
        }
コード例 #12
0
ファイル: ValueConverters.cs プロジェクト: jonbonne/OCTGN
 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();
     }
 }
コード例 #13
0
        public string CreateSHAHash(string User, string Password, string Salt) //Hash and Salt -- Hash SHA512.
        {
            String Text = User + Password;

            System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
            Byte[] HashAsByte     = System.Text.Encoding.UTF8.GetBytes(string.Concat(Text, Salt));
            Byte[] EncryptedBytes = HashTool.ComputeHash(HashAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(EncryptedBytes));
        }
コード例 #14
0
        public static byte[] SHA512Compute(Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            SHA512Managed SHA512 = new SHA512Managed();
            byte[] hash = SHA512.ComputeHash(stream);
            SHA512.Clear();
            return hash;
        }
コード例 #15
0
        public static byte[] SHA512Compute(byte[] data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            SHA512Managed SHA512 = new SHA512Managed();
            byte[] hash = SHA512.ComputeHash(data);
            SHA512.Clear();
            return hash;
        }
コード例 #16
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;
        }
コード例 #17
0
ファイル: Criptografia.cs プロジェクト: LeoVilelaTi/LeoToDo
        public static string GerarHashSha1ComSalt(string senha)
        {
            senha = senha.Trim();

            var HashTool = new SHA512Managed();
            var PhraseAsByte = Encoding.UTF8.GetBytes(string.Concat(senha + SaltText));
            var EncryptedBytes = HashTool.ComputeHash(PhraseAsByte);

            HashTool.Clear();

            return Convert.ToBase64String(EncryptedBytes);
        }
コード例 #18
0
 public JsonResult GenerateSHA512StringFors2s(string inputString)
 {
     using (SHA512 sha512Hash = SHA512.Create())
     {
         //From String to byte array
         byte[] sourceBytes = Encoding.UTF8.GetBytes(inputString);
         byte[] hashBytes   = sha512Hash.ComputeHash(sourceBytes);
         string hash        = BitConverter.ToString(hashBytes).Replace("-", String.Empty);
         System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
         Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hash));
         sha512.Clear();
         var bts = Convert.ToBase64String(EncryptedSHA512);
         return(Json(hash, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #19
0
        public string obtenerHash(string pCadena)
        {
            string textoPlano = pCadena;
            string hashkey    = "*hg849gh84th==3tg7-534d=_";

            System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
            Byte[] HashAsByte     = System.Text.Encoding.UTF8.GetBytes(string.Concat(textoPlano, hashkey));
            Byte[] EncryptedBytes = HashTool.ComputeHash(HashAsByte);
            HashTool.Clear();

            string resultado = Convert.ToBase64String(EncryptedBytes);

            resultado = resultado.Substring(0, 50);

            return(resultado);
        }
コード例 #20
0
        }  // END public String GetHash(String ValueToHash, String ValueLocale, String SaltToUse)

        /// <summary>
        /// This function takes a value you want hashed, uses SHA-512 for strength, and includes a locale extender such as a computer name,
        /// and a salt value that has no intrinsic meaning.  The value returned is the hash string in Base 64.
        /// </summary>
        /// <param name="ValueToHash">This is the value, such as a password.  It will usually be the same over a number of instances on multiple machines.</param>
        /// <param name="ValueLocale">This is a value specific to the machine, such as machine name.  It should be deterministic on every use.</param>
        /// <param name="SaltToUse">This is a value that extends the hash for security.</param>
        /// <returns>The value returned is the hash string in Base 64</returns>
        public String GetHash(String ValueToHash, String ValueLocale, String SaltToUse)
        {
            DateTime dtmMethodStart = DateTime.Now;

            String ReturnValue = "";

            SHA512Managed Hasher = null;

            try
            {
                Hasher = new System.Security.Cryptography.SHA512Managed();

                Byte[] Text2Hash = System.Text.Encoding.UTF8.GetBytes(String.Concat(ValueToHash.Trim(),
                                                                                    ValueLocale.ToUpper(),
                                                                                    SaltToUse.Trim()));

                Byte[] PlateOfHash = Hasher.ComputeHash(Text2Hash);

                ReturnValue = Convert.ToBase64String(PlateOfHash);
            }
            catch (Exception exUnhandled)
            {
                exUnhandled.Data.Add("ValueToHash", ValueToHash ?? "");
                exUnhandled.Data.Add("ValueLocale", ValueLocale ?? "");
                exUnhandled.Data.Add("SaltToUse", SaltToUse ?? "");

                throw;
            } // END catch
            finally
            {
                if (Hasher != null)
                {
                    Hasher.Clear();

                    Hasher.Dispose();

                    Hasher = null;
                }
            }

            return(ReturnValue);
        } // END public  String GetHash(String ValueToHash, String ValueLocale, String SaltToUse)
コード例 #21
0
ファイル: Security.cs プロジェクト: GeraElem/VS
        public static string GetSHA512WithSalt(string strPassword, string strSalt)
        {
            string _strPasswordSalt = strPassword + strSalt;
            SHA512Managed _objSha512 = new SHA512Managed();
            byte[] _objTemporal = null;
            string Retorno = string.Empty;
            StringBuilder sb = new StringBuilder();

            try
            {
                _objTemporal = System.Text.Encoding.UTF8.GetBytes(_strPasswordSalt);
                _objTemporal = _objSha512.ComputeHash(_objTemporal);
                for (int i = 0; i < _objTemporal.Length; i++)
                {
                    sb.Append(_objTemporal[i].ToString("X2"));
                }
            }
            finally { _objSha512.Clear(); }
            return sb.ToString(); ;
        }
コード例 #22
0
        public static string CreatePasswordHash(string _password, string _salt)
        {
            string saltAndPwd = String.Concat(_password, _salt);
            SHA512 sha512     = new System.Security.Cryptography.SHA512Managed();

            byte[] sha512Bytes = System.Text.Encoding.Default.GetBytes(saltAndPwd);

            byte[] cryString = sha512.ComputeHash(sha512Bytes);

            string hashedPwd = string.Empty;

            for (int i = 0; i < cryString.Length; i++)
            {
                hashedPwd += cryString[i].ToString("X");
            }

            sha512.Clear();
            sha512.Dispose();

            return(hashedPwd);
        }
コード例 #23
0
ファイル: Welcome.cs プロジェクト: narugo/SteamGrouper
        public static string CreatePasswordHash(string _password, string _salt)
        {
            string saltAndPwd = String.Concat(_password, _salt);
            SHA512 sha512 = new System.Security.Cryptography.SHA512Managed();

            byte[] sha512Bytes = System.Text.Encoding.Default.GetBytes(saltAndPwd);

            byte[] cryString = sha512.ComputeHash(sha512Bytes);

            string hashedPwd = string.Empty;

            for (int i = 0; i < cryString.Length; i++)
            {
                hashedPwd += cryString[i].ToString("X");
            }

            sha512.Clear();
            sha512.Dispose();

            return hashedPwd;
        }
コード例 #24
0
ファイル: Cryptography.cs プロジェクト: nhanthieugia/BSG
        /// <summary>
        /// Create SHA2 hash
        /// </summary>
        /// <param name="phrase"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string CreateShaHash(string[] phrase, Constants.TypeConvertMD5 type)
        {
            var hashTool = new SHA512Managed();
            var phraseAsByte = Encoding.UTF8.GetBytes(string.Concat(phrase));
            var encryptedBytes = hashTool.ComputeHash(phraseAsByte);
            hashTool.Clear();

            var data = "";

            switch (type)
            {
                case Constants.TypeConvertMD5.Bit:
                    data = BitConverter.ToString(encryptedBytes);
                    break;
                case Constants.TypeConvertMD5.String:
                    data = Convert.ToBase64String(encryptedBytes);
                    break;
            }

            return data;
        }
コード例 #25
0
        }  // END public CryptoStream GetEncryptedStreamObject(Stream objInnerStream)

        /// <summary>
        /// This function takes a value you want hashed and hashes it uses SHA-512 for strength.
        /// The value returned is the hash string in Base 64.
        /// </summary>
        /// <param name="strStringToHash">This is the value, such as a password.  It will usually be the same over a number of instances on multiple machines.</param>
        /// <returns>The value returned is the hash string in Base 64</returns>
        public String GetHash(string strStringToHash)
        {
            String ReturnValue = "";

            SHA512Managed Hasher = null;

            try
            {
                Hasher = new System.Security.Cryptography.SHA512Managed();

                Byte[] Text2Hash = System.Text.Encoding.UTF8.GetBytes(strStringToHash);

                Byte[] PlateOfHash = Hasher.ComputeHash(Text2Hash);

                ReturnValue = Convert.ToBase64String(PlateOfHash);
            }
            catch (Exception exUnhandled)
            {
                exUnhandled.Data.Add("strStringToHash", strStringToHash ?? "");

                throw;
            } // END catch
            finally
            {
                if (Hasher != null)
                {
                    Hasher.Clear();

                    Hasher.Dispose();

                    Hasher = null;
                }
            }

            return(ReturnValue);
        }
コード例 #26
0
ファイル: Crypto.cs プロジェクト: netscout/CloudBread
 //sha512
 public static string SHA512Hash(string Phrase)
 {
     try
     {
         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);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #27
0
        /// <summary>
        /// 计算输入数据的 SHA512 哈希值
        /// </summary>
        /// <param name="strIN">输入的数据.</param>
        /// <returns></returns>
        public static string SHA512Encrypt(string strIN)
        {
            //string strIN = getstrIN(strIN);
            byte[] tmpByte;
            SHA512 sha512 = new SHA512Managed();

            tmpByte = sha512.ComputeHash(StringToBytes(strIN));
            sha512.Clear();

            return BytesToString(tmpByte);
        }
コード例 #28
0
ファイル: Compare-Files.cs プロジェクト: hopenbr/HopDev
        private string GetCheckSum(FileStream _fs)
        {
            //compare contents of files via checksum
            //SHA512 _sha = SHA512.Create();
            SHA512Managed _sha = new SHA512Managed();

            StringBuilder sb = new StringBuilder();

            foreach (byte b in _sha.ComputeHash(_fs))
            {
                sb.Append(b.ToString("x2").ToLower());
            }

            _fs.Close();
            _sha.Clear();
            if (_debug)
            {
                WriteObject(sb.ToString());
            }

            return (sb.ToString());
        }
コード例 #29
0
ファイル: helper.cs プロジェクト: haozhouxu/Jewelry
 /// <summary>
 /// SHA512加密,不可逆转
 /// </summary>
 /// <param name="str">string str:被加密的字符串</param>
 /// <returns>返回加密后的字符串</returns>
 public static string SHA512Encrypt(string str)
 {
     System.Security.Cryptography.SHA512 s512 = new System.Security.Cryptography.SHA512Managed();
     byte[] byte1;
     byte1 = s512.ComputeHash(Encoding.Default.GetBytes(str));
     s512.Clear();
     return Convert.ToBase64String(byte1);
 }
コード例 #30
0
ファイル: Form1.cs プロジェクト: NanQi/demo
 /// <summary>
 /// SHA512加密,不可逆转
 /// </summary>
 private byte[] SHA512Encrypt(byte[] code)
 {
    System.Security.Cryptography.SHA512 s512 = new System.Security.Cryptography.SHA512Managed();
    byte[] result = s512.ComputeHash(code);
    s512.Clear();
    return result;
 }
コード例 #31
0
        public string SHA512Encrypt(string strIN)
        {
            //string strIN = getstrIN(strIN);
            byte[] tmpByte;
            SHA512 sha512 = new SHA512Managed();

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

            return GetStringValue(tmpByte);
        }
コード例 #32
0
ファイル: HashEncrypt.cs プロジェクト: jeanmahai/PublicTools
        public string SHA512Encrypt(string strIN)
        {
            byte[] tmpByte;
            SHA512 sha512 = new SHA512Managed();

            tmpByte = sha512.ComputeHash(System.Text.Encoding.ASCII.GetBytes(strIN));
            string strResult = BitConverter.ToString(tmpByte);
            strResult = strResult.Replace("-", "");
            sha512.Clear();
            sha512 = null;
            return strResult;
        }
コード例 #33
0
ファイル: SgiManager.cs プロジェクト: ArahnaBytes/SGI
        public SteamDepotFile[][] GetSameFiles(SteamDepotFileTypes fileTypes)
        {
            if (fileTypes == SteamDepotFileTypes.None)
                return null;

            List<SteamDepotFile[]> result = new List<SteamDepotFile[]>();
            SHA512Managed sha = new SHA512Managed();

            foreach (List<SteamDepotFile> filesList in files.Values)
            {
                if (filesList.Count > 1)
                {
                    Dictionary<Int64, List<SteamDepotFile>> filesDict = new Dictionary<Int64, List<SteamDepotFile>>();
                    Dictionary<Byte[], List<SteamDepotFile>> hashesDict = new Dictionary<Byte[], List<SteamDepotFile>>();

                    foreach (SteamDepotFile depotFile in filesList)
                    {
                        if ((depotFile.FileType & fileTypes) != SteamDepotFileTypes.None)
                        {
                            FileInfo file = new FileInfo(depotFile.FullName);

                            if (!filesDict.ContainsKey(file.Length))
                                filesDict.Add(file.Length, new List<SteamDepotFile>(1));

                            filesDict[file.Length].Add(depotFile);
                        }
                    }

                    foreach (Int64 fileLength in filesDict.Keys)
                    {
                        if (filesDict[fileLength].Count > 1)
                        {
                            foreach (SteamDepotFile depotFile in filesDict[fileLength])
                            {
                                FileStream stream = File.OpenRead(depotFile.FullName);
                                Byte[] hash1 = sha.ComputeHash(stream);
                                Byte[] hash2 = null;

                                stream.Close();

                                foreach (Byte[] dictHash in hashesDict.Keys)
                                {
                                    Boolean isSameHash = true;

                                    for (Int32 i = 0; i < hash1.Length; i++)
                                    {
                                        if (hash1[i] != dictHash[i])
                                        {
                                            isSameHash = false;
                                            break;
                                        }
                                    }

                                    if (isSameHash)
                                    {
                                        hash2 = dictHash;
                                        break;
                                    }
                                }

                                if (hash2 == null)
                                {
                                    hashesDict.Add(hash1, new List<SteamDepotFile>(1));
                                    hash2 = hash1;
                                }

                                hashesDict[hash2].Add(depotFile);
                            }
                        }
                    }

                    foreach (Byte[] hash in hashesDict.Keys)
                    {
                        if (hashesDict[hash].Count > 1)
                            result.Add(hashesDict[hash].ToArray());
                    }
                }
            }

            sha.Clear();

            return result.ToArray();
        }
コード例 #34
0
 public static byte[] HashPassword(string login, string password, byte[] salt)
 {
     password = login + password;
     var sha = new SHA512Managed();
     byte[] bytes = Encoding.Unicode.GetBytes(password);
     byte[] buffer = new byte[bytes.Length + salt.Length];
     Array.Copy(bytes, buffer, bytes.Length);
     Array.Copy(salt, 0, buffer, bytes.Length, salt.Length);
     var hashed = sha.ComputeHash(buffer);
     sha.Clear();
     return hashed;
 }
コード例 #35
0
        // Login
        public string userLoginQuery(string username, string passwordHash)
        {
            string user;
            SHA512 shaHash = new SHA512Managed();
            byte[] hash = shaHash.ComputeHash(Encoding.UTF8.GetBytes(passwordHash));
            SQLiteCommand userLogin = conn.CreateCommand();
            userLogin.CommandText = @"SELECT username FROM users WHERE username = @user AND password = @passwordHash";
            userLogin.Parameters.Add(new SQLiteParameter("@user", username));
            userLogin.Parameters.Add(new SQLiteParameter("@passwordHash", Convert.ToBase64String(hash)));
            userLogin.CommandType = System.Data.CommandType.Text;
            SQLiteDataReader reader = userLogin.ExecuteReader();

            reader.Read();
            try
            { user = reader["username"].ToString(); }
            catch { user = "******";  }
            userLogin.Dispose();
            shaHash.Clear();
            return user;
        }
コード例 #36
0
        public bool SaveNewEmployee(EmployeeModel model)
        {
            var employeeService = new EmployeeService();
            var roleService = new RoleService();
            try
            {
                //SHA412加密
                string result = "";
                SHA512 sha512 = new SHA512Managed();
                byte[] s = sha512.ComputeHash(Encoding.UTF8.GetBytes("123456"));
                for (int i = 0; i < s.Length; i++)
                {
                    result += s[i].ToString("X2");
                }
                sha512.Clear();

                //添加人员信息
                var newemployee = new employee
                                      {
                                          Name = model.EmployeeName,
                                          Number = model.EmployeeNumber,
                                          RFID = model.Rfid,
                                          Sex = model.Sex,
                                          Password = result.ToLower(),
                                          LogOn = true,
                                          Birthday = Convert.ToDateTime(model.Birthday),
                                          Memo = model.Memo,
                                          State = true
                                      };
                employeeService.Insert(newemployee);

                var roleFlag = new List<long>(); //用来存储角色id,并判断角色id是否重复
                //添加角色信息
                foreach (long t in model.RoleTypeId)
                {
                    //用来判断model中的roleid是否跟roleFlag中的重复
                    int flag = 0;
                    foreach (long l in roleFlag)
                    {
                        if (l == t)
                        {
                            flag = 1;
                        }
                    }
                    //model中的roleid跟roleFlag中的不重复
                    if (flag == 0)
                    {
                        roleFlag.Add(t);
                        var role = new role
                                       {
                                           EmployeeId = employeeService.FindByRfid(model.Rfid).Id,
                                           RoleId = t
                                       };
                        roleService.Insert(role);
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
コード例 #37
0
        public bool SaveModifyEmployee(EmployeeModel model)
        {
            var employeeService = new EmployeeService();
            var roleService = new RoleService();
            string result = "";
            try
            {
                //SHA512加密
                if (model.ConfirmPassWd != null)
                {
                    SHA512 sha512 = new SHA512Managed();
                    byte[] s = sha512.ComputeHash(Encoding.UTF8.GetBytes(model.ConfirmPassWd));
                    for (int i = 0; i < s.Length; i++)
                    {
                        result += s[i].ToString("X2");
                    }
                    sha512.Clear();
                }

                //修改人员信息
                employee newemployee = employeeService.Find(model.EmployeeId);
                newemployee.Name = model.EmployeeName;
                newemployee.Number = model.EmployeeNumber;
                newemployee.RFID = model.Rfid;
                newemployee.LogOn = model.Logon;
                newemployee.Sex = model.Sex;
                newemployee.State = model.state;
                newemployee.Birthday = Convert.ToDateTime(model.Birthday);
                newemployee.Memo = model.Memo;
                if (model.ConfirmPassWd != null)
                {
                    newemployee.Password = result.ToLower();
                }
                employeeService.Update(newemployee);

                //修改角色信息
                //如果增加的角色类型数据库中没有,则插入该角色
                foreach (long t in model.RoleTypeId)
                {
                    List<role> roles = roleService.FindByEmployeeId(model.EmployeeId);
                    int flag = 1;
                    foreach (role role in roles)
                    {
                        if (t == role.RoleId)
                        {
                            flag = 0;
                        }
                    }
                    if (flag == 1)
                    {
                        var role = new role
                                       {
                                           EmployeeId = model.EmployeeId,
                                           RoleId = t
                                       };
                        roleService.Insert(role);
                    }
                }

                //   如果删除了一个角色类型,则在数据库删除对应的角色类型
                List<role> anotherroles = roleService.FindByEmployeeId(model.EmployeeId);
                foreach (role anotherrole in anotherroles)
                {
                    int flag = 1;
                    long delete = anotherrole.RoleId;
                    for (int j = 0; j < model.RoleTypeId.Count; j++)
                    {
                        if (anotherrole.RoleId == model.RoleTypeId[j])
                        {
                            flag = 0;
                        }
                    }
                    if (flag == 1)
                    {
                        roleService = new RoleService();
                        roleService.Delete(
                            roleService.Find(roleService.FindByEmployeeIdAndRoleId(model.EmployeeId, delete).Id));
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
コード例 #38
0
        protected string hash(string userPassword)
        {
            string hesh = userPassword;
            SHA512 shaHash = new SHA512Managed();
            byte[] hash = shaHash.ComputeHash(Encoding.UTF8.GetBytes(hesh));
            shaHash.Clear();

            return  Convert.ToBase64String(hash);
        }
コード例 #39
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bytIN"></param>
        /// <returns></returns>
        public string SHA512Encrypt(byte[] bytIN)
        {
            byte[] tmpByte;
            SHA512 sha512 = new SHA512Managed();

            tmpByte = sha512.ComputeHash(bytIN);
            sha512.Clear();

            return GetStringValue(tmpByte);
        }