Esempio n. 1
1
 public static string GetSha1Hash(this string value)
 {
     var encoding = new UTF8Encoding();
     var hash = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     var hashed = hash.ComputeHash(encoding.GetBytes(value));
     return encoding.GetString(hashed);
 }
Esempio n. 2
0
 public override bool ChangePassword(string username, string newPassword)
 {
     var item = data.MemberInfos.SingleOrDefault(t => t.Username.ToLower() == username.ToLower());
     if (item == null)
         return false;
     Random rnd = new Random();
     item.Salt= new byte[6];
     rnd.NextBytes(item.Salt);
     using (var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider())
         item.Password = sha.ComputeHash(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(newPassword)).Concat(item.Salt).ToArray());
     data.SaveChanges();
     return true;
 }
Esempio n. 3
0
 public override bool Verify(string username, string password)
 {
     var item = data.MemberInfos.SingleOrDefault(t => t.Username == username.ToLower());
     if (item == null)
         return false;
     using (var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider())
     {
         var pwd = sha.ComputeHash(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password)).Concat(item.Salt).ToArray());
         for (int i = 0; i < 20; i++)
             if (pwd[i] != item.Password[i])
                 return false;
         return true;
     }
 }
Esempio n. 4
0
        public static string GetSHA1Hash(string pathName)
        {
            string strResult = "";
            string strHashData = "";

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

            System.Security.Cryptography.SHA1CryptoServiceProvider oSHA1Hasher =
                       new System.Security.Cryptography.SHA1CryptoServiceProvider();

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

                strHashData = System.BitConverter.ToString(arrbytHashValue);
                strHashData = strHashData.Replace("-", "");
                strResult = strHashData;
            }
            catch (System.Exception)
            {
            }

            return (strResult);
        }
Esempio n. 5
0
        public static string GetSHA1Hash(string pathName)
        {
            string strResult = "";
            string strHashData = "";

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

            System.Security.Cryptography.SHA1CryptoServiceProvider oSHA1Hasher =
                       new System.Security.Cryptography.SHA1CryptoServiceProvider();

            try
            {
                oFileStream = GetFileStream(pathName);
                arrbytHashValue = oSHA1Hasher.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);
        }
Esempio n. 6
0
        public static string Generate()
        {
            // Generate random
            var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
            var entropy = new byte[bytes - 4];
            try {
                rnd.GetBytes(entropy);
            } finally {
                rnd.Dispose();
            }

            // Hash
            var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] hash;
            try {
                hash = sha.ComputeHash(entropy);
            } finally {
                sha.Dispose();
            }

            // Compute output
            var raw = new byte[bytes];
            Array.Copy(entropy, 0, raw, 0, bytes - 4);
            Array.Copy(hash, 0, raw, bytes - 4, 4);

            // Convert to Base64
            return Convert.ToBase64String(raw).Replace('+', '!').Replace('/', '~');
        }
 private static string Hash(string toHash)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] data = System.Text.Encoding.ASCII.GetBytes(toHash);
     data = x.ComputeHash(data);
     string o = BitConverter.ToString(data).Replace("-", "").ToUpper();
     return o;
 }
Esempio n. 8
0
        /// <summary>
        /// Retorna el hash SHA1 de la cadena de texto que recibe como parámetro.
        /// </summary>
        /// <param name="unHashed">Cadena de texto a encriptar.</param>
        /// <returns>Hash de la cadena de texto. SHA1.</returns>
        public static string createHash(string unHashed)
        {
            System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] data = System.Text.Encoding.ASCII.GetBytes(unHashed);
            data = x.ComputeHash(data);

            return Convert.ToBase64String(data);
        }
 private static string GenerateAuthorizationToken(string passTypeIdentifier, string serialNumber)
 {
     using (System.Security.Cryptography.SHA1CryptoServiceProvider hasher = new System.Security.Cryptography.SHA1CryptoServiceProvider())
     {
         byte[] data = Encoding.UTF8.GetBytes(passTypeIdentifier.ToLower() + serialNumber.ToLower() + mAuthorizationKey);
         return System.BitConverter.ToString(hasher.ComputeHash(data)).Replace("-", string.Empty).ToLower();
     }
 }
Esempio n. 10
0
        private static string GetCryptographyString(string strSource)
        {
            System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] bytes = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(strSource));
            string result = BitConverter.ToString(bytes, 4, 8).Replace("-","");

            return result;
        }
Esempio n. 11
0
        public static string root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // string root points to MyDocuments

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "-v")
                {
                    Console.WriteLine("asdasd");
                    if (File.Exists(prefs + "/gkey"))
                    {
                            using (System.IO.StreamReader sr = new System.IO.StreamReader(prefs + "/gkey"))
                            {
                                string data = sr.ReadToEnd();
                                string[] f = data.Split('\n');
                                sr.Dispose();
                                if (f[0] == "accepted")
                                {
                                    string HASH = f[1].ToString();
                                    using (System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
                                    {
                                        string hashsum = string.Empty;                  // Empty storage allocator
                                        byte[] da = sha1.ComputeHash(Encoding.Unicode.GetBytes(prefs + "/gkey"));       // byte array
                                        foreach (byte by in data)
                                        {
                                            hashsum += String.Format("{0,2:X2}", by);        // :-)
                                        }

                                        if (hashsum.ToString() != HASH.ToString())
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.Write("SECURITY COMPROMISED!\n\nSHA1 HASH MODIFIED!\nRECORD DOES NOT MATCH G_KEY!\n\nCACHE WILL BE DELETED FOR SECURITY.");
                                            Console.Read();

                                        }

                                        else ;
                                        sha1.Dispose();

                                        try
                                        {
                                            Directory.Delete(prefs);
                                        }

                                        catch { ; }
                                    }
                                }

                            }

                    }
                }

            }

            else
            {
                Console.Write("This is not a standalone application.");
            }
        }
Esempio n. 12
0
 public string EncryptToSHA1(string str)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] str1 = System.Text.Encoding.UTF8.GetBytes(str);
     byte[] str2 = sha1.ComputeHash(str1);
     sha1.Clear();
     (sha1 as IDisposable).Dispose();
     return Convert.ToBase64String(str2);
 }
Esempio n. 13
0
 public string sha1(string input)
 {
     byte[] hash;
     using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
         hash = sha1.ComputeHash(Encoding.Unicode.GetBytes(input));
     var sb = new StringBuilder();
     foreach (byte b in hash) sb.AppendFormat("{0:x2}", b);
     return sb.ToString();
 }
Esempio n. 14
0
 public static string GetSHA1(string pwdata_s)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider osha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     ASCIIEncoding enc = new ASCIIEncoding();
     byte[] pwdata_b = enc.GetBytes(pwdata_s);//password(string) to byte[]
     byte[] pwsha1_b = osha1.ComputeHash(pwdata_b);//ToHash
     string pwsha1_s = BitConverter.ToString(pwsha1_b).Replace("-", "");//hash to string
     return pwsha1_s;
 }
Esempio n. 15
0
 public static string HashString(string Value)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
     data = x.ComputeHash(data);
     string ret = "";
     for (int i = 0; i < data.Length; i++)
         ret += data[i].ToString("x2").ToLower();
     return ret;
 }
Esempio n. 16
0
 public string ComputeSHA1Hash(string input)
 {
     var encrypter = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     using (var sw = new StringWriter())
     {
         foreach (byte b in encrypter.ComputeHash(Encoding.UTF8.GetBytes(input)))
             sw.Write(b.ToString("x2"));
         return sw.ToString();
     }
 }
Esempio n. 17
0
 public static string Encriptar(string valor)
 {
     string clave;
     System.Security.Cryptography.SHA1CryptoServiceProvider provider = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(valor);
     byte[] inArray = provider.ComputeHash(bytes);
     provider.Clear();
     clave = Convert.ToBase64String(inArray);
     return clave;
 }
Esempio n. 18
0
 public static string getHash(Object input)
 {
     // generate a unique id for an arbitrairy object
     MemoryStream memoryStream = new MemoryStream();
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     binaryFormatter.Serialize(memoryStream, input);
     System.Security.Cryptography.SHA1CryptoServiceProvider sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] hash = sha.ComputeHash(memoryStream.ToArray());
     string str = Convert.ToBase64String(sha.Hash);
     return str;
 }
        // used by?
        public static byte[] FileNameToSHA1Bytes(this string Input)
        {
            var SourceHash = default(byte[]);

            var h = new System.Security.Cryptography.SHA1CryptoServiceProvider();

            using (var f = File.OpenRead(Input))
                SourceHash = h.ComputeHash(f);

            return SourceHash;
        }
Esempio n. 20
0
        protected string to_SHA1(string s)
        {
            byte[] data = new byte[256];
            byte[] result;

            System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            // This is one implementation of the abstract class SHA1.
            result = sha.ComputeHash(data);

            return BitConverter.ToString(result);
        }
Esempio n. 21
0
        public static string ComputeHash(string path)
        {
            Image myThumbnail = GetThumb(path);

            using (System.IO.MemoryStream streamout = new System.IO.MemoryStream())
            {
                myThumbnail.Save(streamout, System.Drawing.Imaging.ImageFormat.Bmp);
                streamout.Position = 0;
                System.Security.Cryptography.SHA1 x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
                return BitConverter.ToString(x.ComputeHash(streamout)).Replace("-", "");
            }            
        }
Esempio n. 22
0
        public static string ToHash(this string str)
        {
            var bytes = Encoding.UTF8.GetBytes(str);
            var shaProvider = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            var hashBytes = shaProvider.ComputeHash(bytes);

            var sb = new StringBuilder();
            foreach (var b in hashBytes)
                sb.Append(b.ToString("X2"));

            return sb.ToString();
        }
Esempio n. 23
0
 public static string CalculateSHA1(string text)
 {
     try
     {
         byte[] buffer = Encoding.Default.GetBytes(text);
         System.Security.Cryptography.SHA1CryptoServiceProvider cryptoTransformSHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
         string hash = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
         return(hash);
     }
     catch (Exception x)
     {
         throw new Exception(x.Message);
     }
 }
Esempio n. 24
0
        public static string SHA1Hash(string input)
        {
            System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] data = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = sha.ComputeHash(data);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return(sb.ToString());
        }
Esempio n. 25
0
        public static string SHA1_HashFile(string str_sha1_in, bool remove = true)
        {
            var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();

            byte[] bytes_sha1_in  = File.ReadAllBytes(str_sha1_in);
            byte[] bytes_sha1_out = sha1.ComputeHash(bytes_sha1_in);
            string str_sha1_out   = BitConverter.ToString(bytes_sha1_out);

            if (remove)
            {
                str_sha1_out = str_sha1_out.Replace("-", "");
            }
            return(str_sha1_out);
        }
 public static string GetKey(string salt1, string salt2, string key)
 {
     try
     {
         byte[] buffer = Encoding.Default.GetBytes(salt1 + key + salt2);
         System.Security.Cryptography.SHA1CryptoServiceProvider cryptoTransformSHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
         string hash = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
         return(hash);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 27
0
 public static string EncryptPassword(string senha)
 {
     try
     {
         byte[] buffer = Encoding.Default.GetBytes(senha);
         System.Security.Cryptography.SHA1CryptoServiceProvider cripto = new System.Security.Cryptography.SHA1CryptoServiceProvider();
         string hash = BitConverter.ToString(cripto.ComputeHash(buffer)).Replace("-", "");
         return(hash);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Esempio n. 28
0
        string GetSHA1Hash(string input)
        {
            System.Security.Cryptography.SHA1CryptoServiceProvider hash = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
            bs = hash.ComputeHash(bs);
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }
            string password = s.ToString();

            return(password);
        }
Esempio n. 29
0
        /// <summary>
        /// 转换成RSA1散列字符串
        /// </summary>
        /// <param name="source">源字符串</param>
        /// <param name="toLower">返回哈希值格式 true:英文小写,false:英文大写</param>
        /// <returns>RSA1散列字符串</returns>
        /// <example>
        /// "123456".ToRsa1Hash();
        /// </example>
        public static string ToRsa1Hash(this string source, bool toLower = true)
        {
            var result = string.Empty;

            using (var hash = new System.Security.Cryptography.SHA1CryptoServiceProvider())
            {
                hash.Initialize();
                var bytes = System.Text.Encoding.UTF8.GetBytes(source);
                bytes  = hash.ComputeHash(bytes);
                result = Convert.ToBase64String(bytes);
            }

            return(toLower ? result.ToLower() : result.ToUpper());
        }
Esempio n. 30
0
        public static string Hash(string driverguid)
        {
            System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] textToHash = Encoding.Default.GetBytes(driverguid);
            byte[] result     = sha1.ComputeHash(textToHash);

            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in result)
            {
                s.Append(b.ToString("x2").ToLower());
            }

            return(s.ToString());
        }
Esempio n. 31
0
        public static string GetSHA1EnryptStr(string str)
        {
            System.Security.Cryptography.SHA1 sha;
            ASCIIEncoding enc;
            string        hash = "";

            sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            enc = new ASCIIEncoding();
            byte[] dataToHash = enc.GetBytes(str);
            byte[] dataHashed = sha.ComputeHash(dataToHash);
            hash = BitConverter.ToString(dataHashed).Replace("-", "");
            hash = hash.ToLower();
            return(hash);
        }
Esempio n. 32
0
 public string Criptografar(string text)
 {
     try
     {
         byte[] buffer = Encoding.Default.GetBytes(text);
         System.Security.Cryptography.SHA1CryptoServiceProvider cryptoTransformSHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
         string hash = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
         return hash;
     }
     catch (Exception x)
     {
         throw new Exception(x.Message);
     }
 }
Esempio n. 33
0
 private string SHA1(string phrase)
 {
     byte[] hash;
     using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
     {
         hash = sha1.ComputeHash(Encoding.Unicode.GetBytes(phrase));
         var sb = new StringBuilder();
         foreach (byte b in hash)
         {
             sb.AppendFormat("{0:x2}", b);
         }
         return(sb.ToString());
     }
 }
Esempio n. 34
0
        public static string SHA1HashBase64(string ClearText)
        {
            System.Security.Cryptography.SHA1CryptoServiceProvider Hasher =
                new System.Security.Cryptography.SHA1CryptoServiceProvider();

            byte[] bClear = new byte[ClearText.Length*2];
            for (int i = 0;i<ClearText.Length*2;++i)
                bClear[i] = Convert.ToByte((((i&1)==0)?Convert.ToUInt16(ClearText[i/2])&0xFF:Convert.ToUInt16(ClearText[i/2])>>8));

            Hasher.ComputeHash(bClear);
            byte[] bHash = Hasher.Hash;

            return Convert.ToBase64String(bHash);
        }
Esempio n. 35
0
        public static string Hash1Encrypt(byte[] message)
        {
            var sha256 = new System.Security.Cryptography.SHA1CryptoServiceProvider();

            byte[] hashedDataBytes;
            hashedDataBytes = sha256.ComputeHash(message);
            StringBuilder tmp = new StringBuilder();

            foreach (byte i in hashedDataBytes)
            {
                tmp.Append(i.ToString("x2"));
            }
            return(tmp.ToString());
        }
Esempio n. 36
0
        public static string Hash1Encrypt(string password)
        {
            var sha256 = new System.Security.Cryptography.SHA1CryptoServiceProvider();

            byte[] hashedDataBytes;
            hashedDataBytes = sha256.ComputeHash(Encoding.GetEncoding("UTF-8").GetBytes(password));
            StringBuilder tmp = new StringBuilder();

            foreach (byte i in hashedDataBytes)
            {
                tmp.Append(i.ToString("x2"));
            }
            return(tmp.ToString());
        }
        private string GetSHA1(string value)
        {
            System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();

            byte[] theBytes = sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(value));
            System.Text.StringBuilder sb = new System.Text.StringBuilder(theBytes.Length * 2);

            foreach (byte item in theBytes)
            {
                sb.Append(item.ToString("X2")); //x2 for lowercase
            }

            return(sb.ToString());
        }
Esempio n. 38
0
 private static Torrent ParseBitTorrent(string file)
 {
     using (var stream = File.OpenRead(file))
     {
         var torrent = BEncodedDictionary.DecodeTorrent(stream);
         var it      = ParseBitTorrent((BEncodedDictionary)torrent["info"]);
         using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
         {
             var    rawBytes = ((BEncodedDictionary)torrent["info"]).Encode();
             byte[] infohash = sha1.ComputeHash(rawBytes);
             it.InfoHash = infohash.ToHex();
             return(it);
         }
     }
 }
Esempio n. 39
0
 public static string EncryptStream(Stream stream)
 {
     try
     {
         byte[] ba;
         using (var csp = new System.Security.Cryptography.SHA1CryptoServiceProvider())
             ba = csp.ComputeHash(stream);
         return(Convert.ByteArrayToString(ba));
     }
     catch (Exception ex)
     {
         Log.Debug(ex);
         return(string.Empty);
     }
 }
 /// <summary>
 /// 计算文件的 SHA1 值。
 /// </summary>
 /// <param name="file">文件。</param>
 /// <returns>计算得出的文件 SHA1 值。</returns>
 private static string 计算文件的SHA1(string file)
 {
     byte[] bytes_sha1_out;
     System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
     try
     {
         System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
         bytes_sha1_out = sha1.ComputeHash(fs);
     }
     finally
     {
         fs.Close();
     }
     return(BitConverter.ToString(bytes_sha1_out));
 }
Esempio n. 41
0
        public static string Encrypt(string input)
        {
            byte[] hash;
            using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
            {
                hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(input));
            }
            var sb = new StringBuilder();

            foreach (byte b in hash)
            {
                sb.AppendFormat("{0:x2}", b);
            }
            return(sb.ToString());
        }
Esempio n. 42
0
        /// <summary>
        /// Вычисление хэша пароля, который ввел пользователь
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private static string ComputeHash(User user)
        {
            byte[] hash;
            using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
                hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(user.Password));
            var sb = new StringBuilder();

            foreach (byte b in hash)
            {
                sb.AppendFormat("{0:x2}", b);
            }
            string computedHash = sb.ToString();

            return(computedHash);
        }
        public ActionResult Index(Policy p)
        {
            ViewBag.IsPaid = false;
            PaymentModel model = new PaymentModel();

            p.isMobile = false;
            var PolicyId = SavePolicyHelper.SavePolicy(p, _ps, _us, _iss, _pis, _acs);

            var policy = _ps.GetPolicyById(PolicyId);

            model.mainInsured  = _pis.GetAllInsuredByPolicyId(policy.ID).First();
            model.PolicyNumber = policy.Policy_Number;
            var additionalCharges = _acs.GetAdditionalChargesByPolicyId(PolicyId);

            model.additionalCharge1 = "Без доплаток";
            model.additionalCharge2 = "Без доплаток";
            if (additionalCharges.Count >= 1 && additionalCharges[0] != null)
            {
                model.additionalCharge1 = _acs.GetAdditionalChargeName(additionalCharges[0].ID);
            }
            if (additionalCharges.Count >= 2 && additionalCharges[1] != null)
            {
                model.additionalCharge2 = _acs.GetAdditionalChargeName(additionalCharges[1].ID);
            }

            model.clientId = "180000069";                   //Merchant Id defined by bank to user
            model.amount   = p.Total_Premium.ToString();
            //   "9.95";                         //Transaction amount
            model.oid     = "";                                                                          //Order Id. Must be unique. If left blank, system will generate a unique one.
            model.okUrl   = ConfigurationManager.AppSettings["webpage_url"] + "/Payment/PaymentSuccess"; //URL which client be redirected if authentication is successful
            model.failUrl = ConfigurationManager.AppSettings["webpage_url"] + "/Payment/PaymentFail";    //URL which client be redirected if authentication is not successful
            model.rnd     = DateTime.Now.ToString();                                                     //A random number, such as date/time

            model.currency        = "807";                                                               //Currency code, 949 for TL, ISO_4217 standard
            model.instalmentCount = "";                                                                  //Instalment count, if there is no instalment should left blank
            model.transactionType = "Auth";                                                              //Transaction type
            model.storekey        = "SKEY3545";                                                          //Store key value, defined by bank.
            model.hashstr         = model.clientId + model.oid + model.amount + model.okUrl + model.failUrl + model.transactionType + model.instalmentCount + model.rnd + model.storekey;
            System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            model.hashbytes  = System.Text.Encoding.GetEncoding("ISO-8859-9").GetBytes(model.hashstr);
            model.inputbytes = sha.ComputeHash(model.hashbytes);

            model.hash              = Convert.ToBase64String(model.inputbytes); //Hash value used for validation
            model.retaining_risk    = "No Deductible";
            model.retaining_risk_mk = "Без франшиза";
            model.Pat = policy;
            return(View(model));
        }
Esempio n. 44
0
        public ActionResult SiparisTamamla()
        {
            string userId = User.Identity.GetUserId();
            IEnumerable <Sepet> sepetUrunleri = db.Sepet.Where(a => a.RefAspNetUserId == userId).ToList();

            string ClientId = "100300000";                                 //Bankadan aldığınız mağaza kodu

            string Amount = sepetUrunleri.Sum(a => a.Tutar).ToString();    //sepetteki ürünlerin toplam fiyatı

            string Oid = String.Format("{0:yyyyMMddHmmss}", DateTime.Now); //siparis id olusturuyoruz.her siparis icin farkli olmak zorunda

            string OnayUrl = "http://*****:*****@abc.com";
            ViewBag.UserID          = "AliVeli"; // bu id yi bankanın sanala pos ekranında biz oluşturuyoruz.
            ViewBag.PostURL         = "https://entegrasyon.asseco-see.com.tr/fim/est3Dgate";


            return(View());
        }
Esempio n. 45
0
        string GenerateHashKey()
        {
            //  Reduce browser checking constraint for improving stability when switching compatibility of IE or non-desktop browser
            System.Text.StringBuilder myStr = new System.Text.StringBuilder();
            myStr.Append(Request.Browser.Browser);
            myStr.Append(Request.Browser.Platform);
            //myStr.Append(Request.Browser.MajorVersion);
            //myStr.Append(Request.Browser.MinorVersion);
            //myStr.Append(Request.LogonUserIdentity.User.Value);
            myStr.Append(Request.UserHostAddress);
            myStr.Append(Request.UserHostName);

            System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] hashdata = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(myStr.ToString()));
            return(Convert.ToBase64String(hashdata));
        }
Esempio n. 46
0
 /// <summary>
 /// SHA1加密
 /// </summary>
 /// <param name="content">字符串</param>
 /// <param name="encode">编码</param>
 /// <returns></returns>
 private static string SHA1(string content, Encoding encode)
 {
     try
     {
         System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
         byte[] bytes_in  = encode.GetBytes(content);
         byte[] bytes_out = sha1.ComputeHash(bytes_in);
         string result    = BitConverter.ToString(bytes_out);
         result = result.Replace("-", "");
         return(result);
     }
     catch (Exception ex)
     {
         throw new Exception("SHA1Error:" + ex.Message);
     }
 }
Esempio n. 47
0
        public FrmNewMain()
        {
            InitializeComponent();

            txtTilePath.Text   = @"D:\Allen\Maps";
            txtSqlitePath.Text = @"e:\";
            EnableCtrl(true, false);

            using (var HashProvider = new System.Security.Cryptography.SHA1CryptoServiceProvider())
            {
                Guid Id = new Guid("EF3DD303-3F74-4938-BF40-232D0595EE77");
                DbId = Math.Abs(BitConverter.ToInt32(HashProvider.ComputeHash(Id.ToByteArray()), 0));
            }

            sqliteHelper = new SQLiteHelper();
        }
Esempio n. 48
0
        public void Connect(Uri uri)
        {
            isDone    = false;
            connected = false;
            //var host = uri.Host + (uri.Port == 80 ? "" : ":" + uri.Port.ToString ());
            var req = new Request("GET", uri.ToString());

            req.headers.Set("Upgrade", "websocket");
            req.headers.Set("Connection", "Upgrade");
            var key = WebSocketKey();

            req.headers.Set("Sec-WebSocket-Key", key);
            req.headers.Add("Sec-WebSocket-Protocol", "chat, superchat");
            req.headers.Set("Sec-WebSocket-Version", "13");
            req.headers.Set("Origin", "null");
            req.acceptGzip = false;
            req.Send((Response obj) => {
                if (obj.headers.Get("Upgrade").ToLower() == "websocket" && obj.headers.Get("Connection").ToLower() == "upgrade")
                {
                    var receivedKey = obj.headers.Get("Sec-Websocket-Accept").ToLower();
                    var sha         = new System.Security.Cryptography.SHA1CryptoServiceProvider();
                    sha.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
                    var computedKey = System.Convert.ToBase64String(sha.Hash).ToLower();
                    if (computedKey == receivedKey)
                    {
                        //good to go
                        connected            = true;
                        connection           = req.upgradedConnection;
                        outgoingWorkerThread = new Thread(OutgoingWorker);
                        outgoingWorkerThread.Start();
                        incomingWorkerThread = new Thread(IncomingWorker);
                        incomingWorkerThread.Start();
                        SimpleWWW.Instance.StartCoroutine(Dispatcher());
                        SimpleWWW.Instance.OnQuit(() => {
                            Close(CloseEventCode.CloseEventCodeNotSpecified, "Quit");
                            req.upgradedConnection.client.Close();
                        });
                    }
                    else
                    {
                        //invalid
                        connected = false;
                    }
                }
                isDone = true;
            });
        }
Esempio n. 49
0
        public static String ComputeWebSocketHandshakeSecurityHash09(String secWebSocketKey)
        {
            const String MagicKEY           = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
            String       secWebSocketAccept = String.Empty;

            // 1. Combine the request Sec-WebSocket-Key with magic key.
            String ret = secWebSocketKey + MagicKEY;

            // 2. Compute the SHA1 hash
            System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] sha1Hash = sha.ComputeHash(Encoding.UTF8.GetBytes(ret));

            // 3. Base64 encode the hash
            secWebSocketAccept = Convert.ToBase64String(sha1Hash);

            return(secWebSocketAccept);
        }
Esempio n. 50
0
        public static String ComputeWebSocketHandshakeSecurityHash09(String secWebSocketKey)
        {
            const String MagicKEY = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
            String secWebSocketAccept = String.Empty;

            // 1. Combine the request Sec-WebSocket-Key with magic key.
            String ret = secWebSocketKey + MagicKEY;

            // 2. Compute the SHA1 hash
            System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] sha1Hash = sha.ComputeHash(Encoding.UTF8.GetBytes(ret));

            // 3. Base64 encode the hash
            secWebSocketAccept = Convert.ToBase64String(sha1Hash);

            return secWebSocketAccept;
        }
Esempio n. 51
0
 /// <summary>返回指定文件的SHA1Hash码值</summary>
 /// <param name="path">文件路径</param>
 /// <param name="err">发生错误返回的错误信息</param>
 /// <returns>返回指定文件的SHA1Hash码值</returns>
 public static string GetFileSHA1Hash(string path, ref string err)
 {
     try
     {
         FileStream get_file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
         System.Security.Cryptography.SHA1CryptoServiceProvider getHash = new System.Security.Cryptography.SHA1CryptoServiceProvider();
         byte[] hash_byte = getHash.ComputeHash(get_file);
         string resule    = System.BitConverter.ToString(hash_byte);
         resule = resule.Replace("-", "");
         return(resule);
     }
     catch (Exception ex)
     {
         err = ex.Message;
     }
     return("");
 }
Esempio n. 52
0
        public void ENCRIP(string txt_plano, int campo)
        {
            System.Security.Cryptography.HashAlgorithm obj_hash = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            // Convertir el string original a un array de Bytes
            byte[] cadena_plana = System.Text.Encoding.UTF8.GetBytes(txt_plano);
            byte[] cadena_encrp = obj_hash.ComputeHash(cadena_plana);
            obj_hash.Clear();

            if (campo == 1)
            {
                textBox3.Text = (Convert.ToBase64String(cadena_encrp));
            }
            else
            {
                textBox4.Text = (Convert.ToBase64String(cadena_encrp));
            }
        }
Esempio n. 53
0
        /// <summary>
        /// 指定したファイルのSHA1を取得
        /// </summary>
        /// <param name="file">ファイル</param>
        /// <returns>SHA1</returns>
        private static byte[] GetSHA1(string file)
        {
            //ファイルを開く
            System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            //SHA1CryptoServiceProviderオブジェクトを作成
            System.Security.Cryptography.SHA1CryptoServiceProvider sha1 =
                new System.Security.Cryptography.SHA1CryptoServiceProvider();

            //ハッシュ値を計算する
            byte[] bs = sha1.ComputeHash(fs);

            //ファイルを閉じる
            fs.Close();

            return(bs);
        }
Esempio n. 54
0
        /// <summary>
        /// 签名算法,SHA1加密
        /// </summary>
        /// <param name="_jsapiticket">jsapi_ticket</param>
        /// <param name="_nonceStr">随机字符串(必须与wx.config中的nonceStr相同)</param>
        /// <param name="_timestamp">时间戳(必须与wx.config中的timestamp相同)</param>
        /// <param name="_url">当前网页的URL,不包含#及其后面部分(必须是调用JS接口页面的完整URL)</param>
        /// <returns></returns>
        /// <remarks>2015-9-13 杨浩 创建</remarks>
        public string GetSignature(string _jsapiticket, string _nonceStr, int _timestamp, string _url)
        {
            string string1 = string.Format("jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}", _jsapiticket, _nonceStr, _timestamp, _url);

            //对字符串进行SHA1加密
            using (System.Security.Cryptography.HashAlgorithm iSHA = new System.Security.Cryptography.SHA1CryptoServiceProvider())
            {
                byte[] StrRes = Encoding.Default.GetBytes(string1);
                StrRes = iSHA.ComputeHash(StrRes);
                StringBuilder EnText = new StringBuilder();
                foreach (byte iByte in StrRes)
                {
                    EnText.AppendFormat("{0:x2}", iByte);
                }
                return(EnText.ToString());
            }
        }
Esempio n. 55
0
        public static string ObterResumoEmSha1(string textoDescriptografado)
        {
            try
            {
                byte[] buffer = Encoding.Default.GetBytes(textoDescriptografado);

                System.Security.Cryptography.SHA1CryptoServiceProvider cryptoTransformSHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();

                string resumoEmSha1 = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "").ToLower();

                return(resumoEmSha1);
            }
            catch (Exception erro)
            {
                throw new Exception($"Erro ao obter o resumo em Sha1: {erro.Message}");
            }
        }
Esempio n. 56
0
 public static string getHashedPassword(string password, string login)
 {
     string str = login.ToLower() + password;
     // Create Hash Password
     System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
     byte[] data = encoding.GetBytes(str);
     System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] bytes = sha.ComputeHash(data);
     char[] c = new char[bytes.Length];
     for (int i = 0; i < bytes.Length; i++)
     {
         c[i] = (char)(bytes[i] & 0x7f);
     }
     string hs = string.Empty;
     System.Text.StringBuilder s = new System.Text.StringBuilder();
     hs = s.Append(c).ToString();
     return hs;
 }
Esempio n. 57
0
        /// <summary>
        /// Gets the SHA1 hash.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static string SHA1Hash(string text)
        {
            var SHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();

            byte[] arrayData;
            byte[] arrayResult;
            string result = null;
            string temp = null;

            arrayData = System.Text.Encoding.ASCII.GetBytes(text);
            arrayResult = SHA1.ComputeHash(arrayData);
            for (int i = 0; i < arrayResult.Length; i++) {
                temp = Convert.ToString(arrayResult[i], 16);
                if (temp.Length == 1)
                    temp = "0" + temp;
                result += temp;
            }
            return result;
        }
Esempio n. 58
0
 public string GetHashedValue(string strVal)
 {
     string strHashedValue;
     try
     {
         System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
         byte[] hash = null;
         hash = sha1.ComputeHash(Encoding.ASCII.GetBytes(strVal));
         char[] base64data = new char[(int)(Math.Ceiling((double)hash.Length / 3) * 4)];
         Convert.ToBase64CharArray(hash, 0, hash.Length, base64data, 0);
         string convertedBaseData = new string(base64data);
         strHashedValue = convertedBaseData;
     }
     catch (Exception ex)
     {
         strHashedValue = string.Empty;
     }
     return strHashedValue;
 }
Esempio n. 59
0
        /// <summary>
        /// 签名<br/>
        /// Sign the signature base string.
        /// </summary>
        /// <param name="signatureBaseString">The signature base string to sign.</param>
        /// <returns>The signature.</returns>
        public String sign(String signatureBaseString)
        {
            byte[] ipadArray = new byte[64];
            byte[] opadArray = new byte[64];
            byte[] keyArray = new byte[64];
            System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            int ex = key.Length;
            if (key.Length > 64)
            {
                byte[] temp = sha1.ComputeHash(Encoding.Default.GetBytes(key));
                ex = temp.Length;
                for (int i = 0; i < ex; i++)
                {
                    keyArray[i] = temp[i];
                }
            }
            else
            {
                byte[] temp = Encoding.Default.GetBytes(key);
                for (int i = 0; i < temp.LongLength; i++)
                {
                    keyArray[i] = temp[i];
                }
            }
            for (int i = ex; i < 64; i++)
            {
                keyArray[i] = 0;
            }
            for (int j = 0; j < 64; j++)
            {
                ipadArray[j] = (byte)(keyArray[j] ^ 0x36);
                opadArray[j] = (byte)(keyArray[j] ^ 0x5C);
            }
            byte[] tempResult = sha1.ComputeHash(join(ipadArray, Encoding.Default.GetBytes(signatureBaseString)));

            byte[] sb = sha1.ComputeHash(join(opadArray, tempResult));
            return Convert.ToBase64String(sb);
        }
Esempio n. 60
0
        public static bool Validate(string sid)
        {
            // Basic sanity checks
            if (null == sid) return false;
            if (sid.Length != 32) return false;

            // Decode Base64
            byte[] raw;
            try {
                raw = Convert.FromBase64String(sid.Replace('!', '+').Replace('~', '/'));
            } catch (FormatException) {
                return false; // Not valid Base64
            }

            // Break into components
            var entropy = new byte[bytes - 4];
            var hash = new byte[4];
            Array.Copy(raw, 0, entropy, 0, bytes - 4);
            Array.Copy(raw, bytes - 4, hash, 0, 4);

            // Hash
            var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] buffer;
            try {
                buffer = sha.ComputeHash(entropy);
            } finally {
                sha.Dispose();
            }
            var checkhash = new byte[4];
            Array.Copy(buffer, 0, checkhash, 0, 4);

            // Check hash
            if (!hash.ByteArraysEqual(checkhash)) return false;

            return true;
        }