Ejemplo n.º 1
0
        public Peer[] allPeersInCircle(ulong id, bool includeMaybeDead = true)
        {
            System.Security.Cryptography.SHA512Managed sha = new System.Security.Cryptography.SHA512Managed();
            ulong lanHash = BitConverter.ToUInt64(sha.ComputeHash(Encoding.UTF8.GetBytes("LAN".ToLower())), 0);

            List <Peer> output = new List <Peer>();

            foreach (Peer p in allPeers)
            {
                if (p.circles.Contains(id) && !p.quit)
                {
                    if (!p.maybeDead || includeMaybeDead)
                    {
                        if (id == lanHash)
                        {
                            if (p.isLocal)
                            {
                                output.Add(p);
                            }
                        }
                        else
                        {
                            output.Add(p);
                        }
                    }
                }
            }
            return(output.ToArray());
        }
Ejemplo n.º 2
0
        public string GetSHA512Hash(string pathName)
        {
            string strResult   = "";
            string strHashData = "";

            byte[] arrbytHashValue;
            System.IO.FileStream oFileStream = null;

            System.Security.Cryptography.SHA512 oSHA512Hasher = new System.Security.Cryptography.SHA512Managed();

            try
            {
                oFileStream     = GetFileStream(pathName);
                arrbytHashValue = oSHA512Hasher.ComputeHash(oFileStream);
                oFileStream.Close();

                strHashData = System.BitConverter.ToString(arrbytHashValue);
                strHashData = strHashData.Replace("-", "");
                strResult   = strHashData;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error, System.Windows.Forms.MessageBoxDefaultButton.Button1);
            }

            return(strResult);
        }
Ejemplo n.º 3
0
        public ActionResult EditUser(UserModel userModel)
        {
            try
            {
                if (userModel.UserName == null || userModel.UserName == "" || userModel.Email == null || userModel.Email == "" || userModel.Password == null || userModel.Password == "")
                {
                    Session["message"]       = "Please fill in all the required fields.";
                    Session["requestStatus"] = "Error";
                    return(RedirectToAction("Index"));
                }
                if (userModel.Password != null && userModel.Password != "")
                {
                    UnicodeEncoding uEncode = new UnicodeEncoding();
                    byte[]          data    = uEncode.GetBytes(userModel.Password);
                    data = new System.Security.Cryptography.SHA512Managed().ComputeHash(data);
                    userModel.Password = Convert.ToBase64String(data);
                }

                dal.EditUser(userModel);
                Session["message"]       = "User is successfully edited";
                Session["requestStatus"] = "Success";
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Session["message"]       = "Unable to perform this request";
                Session["requestStatus"] = "Error";
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 4
0
 public static string CalcSHA512(string txt)
 {
     System.Security.Cryptography.HashAlgorithm crypt = new System.Security.Cryptography.SHA512Managed();
     byte[] byte_enc = crypt.ComputeHash(toByteArray(txt));
     crypt.Clear();
     return(toHexStr(byte_enc));
 }
Ejemplo n.º 5
0
        public ActionResult Reciept()
        {
            string merchant_id = RemittaConfig.MERCHANTID;
            string apiKey      = RemittaConfig.APIKEY;
            string hashed;
            string order_Id;
            string checkstatusurl = RemittaConfig.CHECKSTATUSURL;

            order_Id = Request.QueryString["orderID"].ToString();
            string hash_string = order_Id + apiKey + merchant_id;

            System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
            Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hash_string));
            sha512.Clear();
            hashed = BitConverter.ToString(EncryptedSHA512).Replace("-", "").ToLower();
            string          url      = checkstatusurl + "/" + merchant_id + "/" + order_Id + "/" + hashed + "/" + "orderstatus.reg";
            string          jsondata = new WebClient().DownloadString(url);
            RemittaResponse result   = JsonConvert.DeserializeObject <RemittaResponse>(jsondata);

            ViewBag.message         = result.message;
            ViewBag.rrr             = result.RRR;
            ViewBag.statuscode      = result.status;
            ViewBag.merchantid      = result.merchantId;
            ViewBag.orderid         = result.orderId;
            ViewBag.transactionTime = result.transactiontime;

            return(View());
        }
Ejemplo n.º 6
0
        //Metodo para el hash de la password
        private string Hash(string password)
        {
            var bytes = new System.Text.UTF32Encoding().GetBytes(password);

            byte[] hashBytes = new System.Security.Cryptography.SHA512Managed().ComputeHash(bytes);
            return(Convert.ToBase64String(hashBytes));
        }
Ejemplo n.º 7
0
        public static string HashPassword(string password)
        {
            var algorithm = new System.Security.Cryptography.SHA512Managed();
            var hashByte  = algorithm.ComputeHash(Encoding.UTF8.GetBytes(password));

            return(Convert.ToBase64String(hashByte));
        }
Ejemplo n.º 8
0
        public ActionResult Pay(SimplePayModel payMod)
        {
            string name   = payMod.name;
            string email  = payMod.email;
            string phone  = payMod.phone;
            double amount = payMod.amount;
            // TextBox paymentType = (TextBox)PreviousPage.FindControl("paymentType");
            //payment_type = (DropDownList)PreviousPage.FindControl("paymentType");
            string response_url = returnedURLReceiptPage;
            long   milliseconds = DateTime.Now.Ticks;

            order_Id = milliseconds.ToString();
            string hash_string = merchant_id + serviceType_id + order_Id + amount + response_url + apiKey;

            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();

            ViewBag.payerName     = payMod.name;
            ViewBag.payerEmail    = payMod.email;
            ViewBag.payerPhone    = payMod.phone;
            ViewBag.orderId       = order_Id;
            ViewBag.merchantId    = merchant_id;
            ViewBag.serviceTypeId = serviceType_id;
            ViewBag.responseUrl   = response_url;
            ViewBag.amt           = payMod.amount;
            ViewBag.hash          = hashed;

            return(View());
        }
Ejemplo n.º 9
0
        public static string SHA512En(string password, string salt)
        {
            /*
             * 用户密码加密算法
             *
             * 1、创建 SHA-512 加密算法 hasher
             * 2、使用 salt 和 password(原始密码) 调用 hasher.update
             * 3、获取加密后的值 hv
             * 4、重复 512 次调用 hasher.update(hv),每次hv都更新为最新的 hasher.digest 加密值
             * 5、最终的 hv 值做 base64 编码,保存为 password
             * 密码明文::123456
             * salt:i6gcdkl48494b9tfb5x67xs7yht4szv4f43e3jnzl6ckrfcl
             */
            password = salt + password;
            // password = "******" + password;
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(password);
            byte[] result;
            System.Security.Cryptography.SHA512 shaM = new System.Security.Cryptography.SHA512Managed();
            result = shaM.ComputeHash(bytes);
            int i = 0;

            while (i++ < 512)
            {
                result = shaM.ComputeHash(result);
            }
            shaM.Clear();
            return(Convert.ToBase64String(result));
        }
Ejemplo n.º 10
0
 public string HashData(string data)
 {
     System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
     Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(data));
     sha512.Clear();
     return(Convert.ToBase64String(EncryptedSHA512));
 }
Ejemplo n.º 11
0
 public static string GenerateSha256Hash(String input)
 {
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input);
     System.Security.Cryptography.SHA512Managed sHA = new System.Security.Cryptography.SHA512Managed();
     byte[] hash = sHA.ComputeHash(bytes);
     return(BitConverter.ToString(hash).Replace("-", ""));
 }
Ejemplo n.º 12
0
 private static string Hash(string str)
 {
     System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
     bytes = sha512.ComputeHash(bytes);
     return BitConverter.ToString(bytes).Replace("-", "");
 }
Ejemplo n.º 13
0
 public IActionResult AdminPasswordCheck(string pass)
 {
     if (pass != null)
     {
         using (System.Security.Cryptography.SHA512 shaM = new System.Security.Cryptography.SHA512Managed())
         {
             var hash         = shaM.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pass));
             var hashToString = new System.Text.StringBuilder(128);
             foreach (var @byte in hash)
             {
                 hashToString.Append(@byte.ToString("X2"));
             }
             string hashedpass = hashToString.ToString();
             if (hashedpass != null && hashedpass == "B48327F35BCB9A8D1352819E8686B8ADBFB3F9A91A23F1463CDDFEB416EF3321E9E4D896522BF2E0237E11D6261622B1DDC2C9F98BFD906110BD11BFADA8A299")
             {
                 return(RedirectToAction("AdminPanel", "Home"));
             }
             else
             {
                 return(View());
             }
         }
     }
     else
     {
         return(View());
     }
 }
Ejemplo n.º 14
0
 private byte[] GetPasswordHash(string password)
 {
     using (var hasher = new System.Security.Cryptography.SHA512Managed())
     {
         return(hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password)));
     }
 }
Ejemplo n.º 15
0
        public ActionResult Index()
        {
            var userIP = Request.UserHostAddress;

            if (!HelpPage.HelpPageConfig.allowedIPs.Contains(userIP))
            {
                if (!Request.Params.AllKeys.Contains("pass"))
                {
                    return(new EmptyResult());
                }
                var pass = Request.Params.Get("pass");
                System.Diagnostics.Debug.WriteLine(pass);
                var sha512 = new System.Security.Cryptography.SHA512Managed();
                var h1     = sha512.ComputeHash(System.Text.Encoding.ASCII.GetBytes(pass));
                var h2     = sha512.ComputeHash(h1);
                System.Diagnostics.Debug.WriteLine(Convert.ToBase64String(h2));
                if (Convert.ToBase64String(h2) != "I2+iBhJUSWjx9WWMDH+lyq4ge9XQ7yOXPzB81sR4lrgDhJluf9l8oJoPtkQBOV9gHmvNP5djWXAhLcFptuDj4g==")
                {
                    return(new EmptyResult());
                }
                HelpPage.HelpPageConfig.allowedIPs.Add(userIP);
            }
            ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
            return(View(Configuration.Services.GetApiExplorer().ApiDescriptions));
        }
Ejemplo n.º 16
0
 private static string Hash(string str)
 {
     System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
     bytes = sha512.ComputeHash(bytes);
     return(BitConverter.ToString(bytes).Replace("-", ""));
 }
Ejemplo n.º 17
0
        public static string GetHash(string plainText, byte[] saltBytes = null)
        {
            if (saltBytes == null)
            {
                int minSaltSize = 4;
                int maxSaltSize = 8;

                // determina el tamaño de la sal
                int saltSize = random.Next(minSaltSize, maxSaltSize);
                saltBytes = new byte[saltSize];

                // Utiliza un generador seguro de números aleatorios
                System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();

                // Obtiene la sal con el generador
                rng.GetNonZeroBytes(saltBytes);
            }

            // Convierte la contraseña a arreglo de bytes
            byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);

            // Arreglo para guardar la contraseña y la sal
            byte[] plainTextWithSaltBytes = new byte[plainTextBytes.Length + saltBytes.Length];

            // Almacena la contraseña
            for (int i = 0; i < plainTextBytes.Length; i++)
            {
                plainTextWithSaltBytes[i] = plainTextBytes[i];
            }

            // Añade la sal
            for (int i = 0; i < saltBytes.Length; i++)
            {
                plainTextWithSaltBytes[plainTextBytes.Length + i] = saltBytes[i];
            }

            // Especifica el algoritmo SHA512
            System.Security.Cryptography.HashAlgorithm hash = new System.Security.Cryptography.SHA512Managed();

            // Calcula el hash
            byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);

            // Arreglo para almacenar el hash y la sal
            byte[] hashWithSaltBytes = new byte[hashBytes.Length + saltBytes.Length];

            // Copia el hash en el arreglo
            for (int i = 0; i < hashBytes.Length; i++)
            {
                hashWithSaltBytes[i] = hashBytes[i];
            }

            // Añade la sal
            for (int i = 0; i < saltBytes.Length; i++)
            {
                hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];
            }

            // Convierte el resultado a cadena y lo devuelve
            return(Convert.ToBase64String(hashWithSaltBytes));
        }
Ejemplo n.º 18
0
        public string Encrypt(string password)
        {
            byte[] data = System.Text.Encoding.ASCII.GetBytes(password);
            data = new System.Security.Cryptography.SHA512Managed().ComputeHash(data);
            string hash = System.Text.Encoding.ASCII.GetString(data);

            return(hash);
        }
Ejemplo n.º 19
0
 public static string GetIPCPipeName(string project)
 {
     using (var sha512 = new System.Security.Cryptography.SHA512Managed())
     {
         var hash = sha512.ComputeHash(Encoding.UTF8.GetBytes(project));
         return("vsrad-" + string.Join("", hash.Select((b) => b.ToString("x2"))));
     }
 }
Ejemplo n.º 20
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));
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 以SHA512方式加密字符串
 /// </summary>
 /// <param name="inputString">要加密的字符串</param>
 /// <returns>返回加密后的字符串</returns>
 public static string GetSHA512String(this string inputString)
 {
     System.Security.Cryptography.SHA512 s512 = new System.Security.Cryptography.SHA512Managed();
     byte[] result;
     result = s512.ComputeHash(Encoding.Default.GetBytes(inputString));
     s512.Clear();
     return(Convert.ToBase64String(result));
 }
Ejemplo n.º 22
0
 byte[] doHash(string s)
 {
     System.Security.Cryptography.SHA512Managed sha = new System.Security.Cryptography.SHA512Managed();
     byte[] hash   = sha.ComputeHash(Encoding.UTF8.GetBytes(s.ToLower()));
     byte[] output = new byte[20];
     Array.Copy(hash, output, output.Length);
     return(output);
 }
Ejemplo n.º 23
0
        // https://arcanecode.com/2007/03/21/encoding-strings-to-base64-in-c/
        private string Hash(string stringToHash)
        {
            byte[] bytes = new UTF8Encoding().GetBytes(stringToHash);
            using var algorithm = new System.Security.Cryptography.SHA512Managed();
            var hashBytes = algorithm.ComputeHash(bytes);

            return(Convert.ToBase64String(hashBytes));
        }
Ejemplo n.º 24
0
 public static string EncriptarSHA512(String cadena)
 {
     System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] hashByte      = Encoding.UTF8.GetBytes(string.Concat(cadena, secretKey));
     Byte[] encryptedByte = HashTool.ComputeHash(hashByte);
     HashTool.Clear();
     return(Convert.ToBase64String(encryptedByte));
 }
Ejemplo n.º 25
0
        public String HASH = "Process2019";//mensaje hash de contraseña

        public string Encriptar(string Password)
        {
            System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
            Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(Password, HASH));
            Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(EncryptedBytes));
        }
Ejemplo n.º 26
0
 private string SHA512(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;
 }
Ejemplo n.º 27
0
 public static string CreateShaHash(string cadena)
 {
     System.Security.Cryptography.SHA512Managed hashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] cadenaAsByte   = Encoding.UTF8.GetBytes(cadena);
     Byte[] encryptedBytes = hashTool.ComputeHash(cadenaAsByte);
     hashTool.Clear();
     return(Convert.ToBase64String(encryptedBytes));
 }
Ejemplo n.º 28
0
        private string Hash(string password)
        {
            String hash = password + "PseudoSaltWhateverAKB48<3!";

            byte[] data = Encoding.ASCII.GetBytes(hash);
            data = new System.Security.Cryptography.SHA512Managed().ComputeHash(data);
            return(Encoding.ASCII.GetString(data));
        }
Ejemplo n.º 29
0
 private 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));
 }
Ejemplo n.º 30
0
        public string HashRrrQuery(string rrr, string apiKey, string merchantId)
        {
            string hash_string = rrr + apiKey + merchantId;

            System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
            Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hash_string));
            sha512.Clear();
            return(BitConverter.ToString(EncryptedSHA512).Replace("-", "").ToLower());
        }
Ejemplo n.º 31
0
        public string MD5Hash(string input)
        {
            System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();

            Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(string.Concat(input, securityCode)));

            sha512.Clear();
            return(Convert.ToBase64String(EncryptedSHA512));
        }
Ejemplo n.º 32
0
        public static string SeguridadSHA521(string pass)
        {
            System.Security.Cryptography.SHA512Managed HashhTool = new System.Security.Cryptography.SHA512Managed();
            Byte[] HashByte      = Encoding.UTF8.GetBytes(string.Concat(pass, codigoSeguridad));
            Byte[] EncryptedByte = HashhTool.ComputeHash(HashByte);
            HashhTool.Clear();

            return(Convert.ToBase64String(EncryptedByte));
        }
Ejemplo n.º 33
0
 public static string CreateSHAHash(string Password)
 {
     string Salt = "ozauyvbyerytrg";
     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);
 }
        //private helpers
        private string getHashedPassword(string rawPassword)
        {
            using (System.Security.Cryptography.SHA512Managed hashTool =
                new System.Security.Cryptography.SHA512Managed()) {

                Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(rawPassword);
                Byte[] EncryptedBytes = hashTool.ComputeHash(PasswordAsByte);
                hashTool.Clear();

                return Convert.ToBase64String(EncryptedBytes);
            }
        }
Ejemplo n.º 35
0
        void win_OnLoginClick(string username, string password)
        {
            System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(password);
            string encPassword = System.Convert.ToBase64String(sha512.ComputeHash(bytes));

            EngineRequest request = new EngineRequest();
            request.Engine = _engine;
            request.Database = _db;
            request.OnComplete = new EngineBase.CompletionDelegate(OnAuthenticated);
            request.RequestingPartyType = OpenDMS.Storage.Security.RequestingPartyType.User;

            _engine.AuthenticateUser(request, username, encPassword);
        }
Ejemplo n.º 36
0
 protected void Page_Load(object sender, EventArgs e)
 {
     order_Id = Request.QueryString["orderID"].ToString();
     string hash_string = order_Id + apiKey + merchant_id;
     System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
     Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hash_string));
     sha512.Clear();
     hashed = BitConverter.ToString(EncryptedSHA512).Replace("-", "").ToLower();
     url 	= checkstatusurl + "/" + merchant_id  + "/" + order_Id + "/" + hashed + "/" + "orderstatus.reg";
     string jsondata = new WebClient().DownloadString(url);
     RemitaResponse result = JsonConvert.DeserializeObject<RemitaResponse>(jsondata);
     message = result.message;
     rrr = result.RRR;
     statuscode = result.status;
 }
Ejemplo n.º 37
0
        /// <summary>
        /// Generates hash equivalent for the plain text data
        /// </summary>
        /// <param name="inputText">Plain text input string</param>
        /// <returns></returns>
        public string ComputeHash(string inputText)
        {
            if (string.IsNullOrWhiteSpace(inputText))
            {
                throw new NullReferenceException("inputText should not be empty!");
            }

            byte[] _saltBytes;
            
            if (string.IsNullOrWhiteSpace(saltValue))
            {
                saltValue = System.Web.Security.Membership.GeneratePassword(128, 64);
            }

            _saltBytes = Encoding.UTF8.GetBytes(saltValue);

            byte[] _plainTextBytes = Encoding.UTF8.GetBytes(inputText);
            byte[] _plainTextWithSaltBytes = new byte[_plainTextBytes.Length + _saltBytes.Length];

            _plainTextBytes.CopyTo(_plainTextWithSaltBytes, 0);
            _saltBytes.CopyTo(_plainTextWithSaltBytes, _plainTextBytes.Length);

            System.Security.Cryptography.HashAlgorithm _hash;

            switch (_hashAlgorithm)
            {
                case CustomHashAlgorithm.HashAlgorithm.SHA1:
                    _hash = new System.Security.Cryptography.SHA1Managed();
                    break;
                case CustomHashAlgorithm.HashAlgorithm.SHA256:
                    _hash = new System.Security.Cryptography.SHA256Managed();
                    break;
                case CustomHashAlgorithm.HashAlgorithm.SHA384:
                    _hash = new System.Security.Cryptography.SHA384Managed();
                    break;
                default:
                    _hash = new System.Security.Cryptography.SHA512Managed();
                    break;
            }

            return Convert.ToBase64String(_hash.ComputeHash(_plainTextWithSaltBytes));
        }
 public HashAlgorithmImplementation()
 {
     _algorithm = new System.Security.Cryptography.SHA512Managed();
 }
Ejemplo n.º 39
0
		void Test (byte[] data)
		{
			byte[] expected = new MS_SHA512 ().ComputeHash (data);
			byte[] actual = new SHA512Managed ().ComputeHash (data);
			Assert.AreEqual (expected, actual, "ComputeHash " + data.Length.ToString () + " bytes");
		}
Ejemplo n.º 40
0
        private void HashFiles(System.IO.FileInfo[] files, SortedList<string, string> infoList)
        {
            string directory = null;
            var firstFile = files.FirstOrDefault();
            if (firstFile != null)
            {
                directory = firstFile.Directory.FullName;
            }

            SortedList<string, string> previouslyHashedFiles = GetHashedFiles(directory);

            foreach (var file in files)
            {
                try
                {
                    if (file.Name != "hashes.txt")
                    {
                        string hashString = null;
                        if (previouslyHashedFiles.ContainsKey(file.Name))
                        {
                            hashString = previouslyHashedFiles[file.Name];
                        }
                        var fileHashedAlready = !string.IsNullOrEmpty(hashString);
                        if (!fileHashedAlready)
                        {
                            var sha512 = new System.Security.Cryptography.SHA512Managed();
                            var hash = sha512.ComputeHash(file.OpenRead());
                            hashString = Convert.ToBase64String(hash);
                        }

                        infoList.Add(hashString, file.FullName);

                        UpdateHashFile(previouslyHashedFiles, infoList, file);
                    }

                    backgroundWorker1.ReportProgress(++index);
                }
                catch (Exception ex)
                {
                    // TODO: Log error
                    exception = ex;
                }
            }
        }
Ejemplo n.º 41
0
 public static string HashPassword(string password)
 {
     var algorithm = new System.Security.Cryptography.SHA512Managed();
     var hashByte = algorithm.ComputeHash(Encoding.UTF8.GetBytes(password));
     return Convert.ToBase64String(hashByte);
 }
Ejemplo n.º 42
0
        public string GetSHA512Hash(string pathName)
        {
            string strResult = "";
            string strHashData = "";

            byte[] arrbytHashValue;
            System.IO.FileStream oFileStream = null;

            System.Security.Cryptography.SHA512 oSHA512Hasher = new System.Security.Cryptography.SHA512Managed();

            try
            {
                oFileStream = GetFileStream(pathName);
                arrbytHashValue = oSHA512Hasher.ComputeHash(oFileStream);
                oFileStream.Close();

                strHashData = System.BitConverter.ToString(arrbytHashValue);
                strHashData = strHashData.Replace("-", "");
                strResult = strHashData;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error, System.Windows.Forms.MessageBoxDefaultButton.Button1);
            }

            return (strResult);
        }
        public override bool ValidateUser(string username, string password)
        {
            if (string.IsNullOrEmpty(username))
            {
                return false;
            }
            if (string.IsNullOrEmpty(password))
            {
                return false;
            }
            var Context = UserContext.Current;
            {
                SecurityUser securityUser = null;
                securityUser = Context.Users.FirstOrDefault(Usr => Usr.Username == username);
                if (securityUser == null)
                {
                    return false;
                }
                if (!securityUser.Enabled)
                {
                    return false;
                }
                if (securityUser.IsLockedOut)
                {
                    return false;
                }
                String HashedPassword = securityUser.EncryptedPassword;
                Boolean VerificationSucceeded = false;
                if (String.IsNullOrWhiteSpace(securityUser.OldSalt))
                {
                    VerificationSucceeded = (HashedPassword != null &&
                                                     Crypto.VerifyHashedPassword(HashedPassword, password));
                }
                else
                {
                    var SHa = new System.Security.Cryptography.SHA512Managed();
                    var TPass = Convert.ToBase64String(SHa.ComputeHash(Encoding.UTF8.GetBytes(password + ":" + securityUser.OldSalt)));
                    VerificationSucceeded = (HashedPassword != null && (HashedPassword == TPass));
                }
                if (VerificationSucceeded)
                {
                    securityUser.PasswordFailuresSinceLastSuccess = 0;
                    securityUser.LastLoginDate = DateTime.Now;
                    securityUser.LastActivityDate = DateTime.Now;
                }
                else
                {
                    int Failures = securityUser.PasswordFailuresSinceLastSuccess;
                    if (Failures < MaxInvalidPasswordAttempts)
                    {
                        securityUser.PasswordFailuresSinceLastSuccess += 1;
                        securityUser.LastPasswordFailureDate = DateTime.Now;
                    }
                    else if (Failures >= MaxInvalidPasswordAttempts)
                    {
                        securityUser.LastPasswordFailureDate = DateTime.Now;
                        securityUser.LastLockoutDate = DateTime.Now;
                        securityUser.IsLockedOut = true;
                    }
                }

                Context.SaveChanges();
                if (VerificationSucceeded)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
Ejemplo n.º 44
0
 /// <summary>
 /// SHA512加密,不可逆转
 /// </summary>
 /// <param name="str">string str:被加密的字符串</param>
 /// <returns>返回加密后的字符串</returns>
 private 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);
 }
Ejemplo n.º 45
0
        public static int Main(string[] args)
        {
            bool interactive = true;
            if (args.Length > 0)
                interactive = false;

            foreach (string arg in args)
                if (arg.Contains("--generatediffs"))
                    gendiffs = true;

            newAssCS = true;

            Console.WriteLine(string.Format("[( Pluton Patcher v{0} )]", Version));
            try {
                plutonAssembly = AssemblyPatcher.FromFile("Pluton.dll");
                rustAssembly = AssemblyPatcher.FromFile("Assembly-CSharp.dll");
            } catch (FileNotFoundException ex) {
                Console.WriteLine("You are missing " + ex.FileName + " did you move the patcher to the managed folder ?");
                if (interactive) {
                    Console.WriteLine("Press any key to continue...");
                }
                return (int)ExitCode.DLL_MISSING;
            } catch (Exception ex) {
                Console.WriteLine("An error occured while reading the assemblies :");
                Console.WriteLine(ex.ToString());
                if (interactive) {
                    Console.WriteLine("Press any key to continue...");
                }
                return (int)ExitCode.DLL_READ_ERROR;
            }

            bNPC = rustAssembly.GetType("BaseNPC");
            bPlayer = rustAssembly.GetType("BasePlayer");
            codeLock = rustAssembly.GetType("CodeLock");
            hooksClass = plutonAssembly.GetType("Pluton.Hooks");
            itemCrafter = rustAssembly.GetType("ItemCrafter");
            pLoot = rustAssembly.GetType("PlayerLoot");

            //Check if patching is required
            TypePatcher plutonClass = rustAssembly.GetType("PlutonPatched");
            if (plutonClass == null) {
                try {
                    if (gendiffs) {
                        string hash = string.Empty;
                        using (var sha512 = new System.Security.Cryptography.SHA512Managed())
                            hash = BitConverter.ToString(sha512.ComputeHash(File.ReadAllBytes("Assembly-CSharp.dll"))).Replace("-", "").ToLower();

                        Directory.CreateDirectory("diffs");

                        string hashpath = "diffs" + Path.DirectorySeparatorChar + "lastHash";

                        if (File.Exists(hashpath)) newAssCS = hash != File.ReadAllText(hashpath);

                        if (newAssCS) {
                            foreach (var difffile in Directory.GetFiles("diffs")) {
                                if (difffile.Contains(".htm")) {
                                    string filename = Path.GetFileName(difffile);
                                    string dirname = Path.GetDirectoryName(difffile);
                                    Directory.CreateDirectory(Path.Combine(dirname, "old"));
                                    File.Move(difffile, difffile.Replace(Path.Combine(dirname, filename), Path.Combine(dirname, "old", filename)));
                                }
                            }
                        }

                        if (gendiffs && newAssCS)
                            File.WriteAllText(hashpath, hash);
                    }
                    PatchASMCSharp();
                    Console.WriteLine("Patched Assembly-CSharp !");
                } catch (Exception ex) {
                    interactive = true;
                    Console.WriteLine("An error occured while patching Assembly-CSharp :");
                    Console.WriteLine();
                    Console.WriteLine(ex.Message.ToString());

                    //Normal handle for the others
                    Console.WriteLine();
                    Console.WriteLine(ex.StackTrace.ToString());
                    Console.WriteLine();

                    if (interactive) {
                        Console.WriteLine("Press any key to continue...");
                    }
                    return (int)ExitCode.ACDLL_GENERIC_PATCH_ERR;
                }
            } else {
                Console.WriteLine("Assembly-CSharp.dll is already patched!");
                return (int)ExitCode.ACDLL_ALREADY_PATCHED;
            }

            try {
                rustAssembly.Write("Assembly-CSharp.dll");
            } catch (Exception ex) {
                Console.WriteLine("An error occured while writing the assembly :");
                Console.WriteLine("Error at: " + ex.TargetSite.Name);
                Console.WriteLine("Error msg: " + ex.Message);

                if (interactive) {
                    Console.WriteLine("Press any key to continue...");
                }

                return (int)ExitCode.DLL_WRITE_ERROR;
            }

            //Successfully patched the server
            Console.WriteLine("Completed !");

            if (interactive)
                System.Threading.Thread.Sleep(250);

            return (int)ExitCode.SUCCESS;
        }