コード例 #1
0
ファイル: DataContext.cs プロジェクト: dansiegel/ShinyPush
        public static string HashText(string text)
        {
            var salt   = nameof(DataContext);
            var hasher = new SHA1CryptoServiceProvider();

            byte[] textWithSaltBytes = Encoding.UTF8.GetBytes(string.Concat(text, salt));
            byte[] hashedBytes       = hasher.ComputeHash(textWithSaltBytes);
            hasher.Clear();
            return(Convert.ToBase64String(hashedBytes));
        }
コード例 #2
0
        public string EncryptSHA1(string str)
        {
            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();

            byte[] str1 = Encoding.UTF8.GetBytes(str);
            byte[] str2 = sha1.ComputeHash(str1);
            sha1.Clear();
            (sha1 as IDisposable).Dispose();
            return(Convert.ToBase64String(str2));
        }
コード例 #3
0
        public override byte[] digest()
        {
            //return md.digest();
            cs.Close();
            byte[] result = md.Hash;
            md.Clear();
            init(); //Reinitiazing hash objects

            return(result);
        }
コード例 #4
0
ファイル: AppUtils.cs プロジェクト: punkrocker/YoyoTravel
        public static string SHA1Hash(string origin)
        {
            SHA1 sha1 = new SHA1CryptoServiceProvider();

            byte[] bytes_sha1_in  = UTF8Encoding.Default.GetBytes(origin);
            byte[] bytes_sha1_out = sha1.ComputeHash(bytes_sha1_in);
            sha1.Clear();
            (sha1 as IDisposable).Dispose();
            return(Convert.ToBase64String(bytes_sha1_out));
        }
コード例 #5
0
        /// <summary>
        /// 计算输入数据的 SHA1 哈希值
        /// </summary>
        /// <param name="strIN">输入的数据.</param>
        /// <returns></returns>
        public static string SHA1Encrypt(string strIN)
        {
            byte[] tmpByte;
            SHA1   sha1 = new SHA1CryptoServiceProvider();

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

            return(BytesToString(tmpByte));
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bytIN"></param>
        /// <returns></returns>
        public string SHA1Encrypt(byte[] bytIN)
        {
            byte[] tmpByte;
            SHA1   sha1 = new SHA1CryptoServiceProvider();

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

            return(GetStringValue(tmpByte));
        }
コード例 #7
0
 byte[] GenKey(byte[] key)
 {
     for (int x = 0; x < 10000; x++)
     {
         SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
         sha1.TransformBlock(key, 0, key.Length, key, 0);
         key = sha1.TransformFinalBlock(ASCIIEncoding.ASCII.GetBytes("fuckoff"), 0, 7);
         sha1.Clear();
     }
     return(key);
 }
コード例 #8
0
        public static string SHA1Encrypt(string password)
        {
            //string strIN = getstrIN(strIN);
            byte[] tmpByte;
            SHA1   sha1 = new SHA1CryptoServiceProvider();

            tmpByte = sha1.ComputeHash(GetKeyByteArray(password));
            sha1.Clear();

            return(GetStringValue(tmpByte));
        }
コード例 #9
0
        /// <summary>
        /// 微信sha1加密
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string Sha1WeChat(string key)
        {
            var bytes = Encoding.UTF8.GetBytes(key);
            var sha1CryptoServiceProvider = new SHA1CryptoServiceProvider();
            var hash = sha1CryptoServiceProvider.ComputeHash(bytes);

            sha1CryptoServiceProvider.Clear();
            // 注意,不能用这个
            //string output = Convert.ToBase64String(temp2);
            return(BitConverter.ToString(hash).Replace("-", "").ToLower());
        }
コード例 #10
0
ファイル: ShaHelper.cs プロジェクト: jackjet870/xlwx
        /// <summary>
        /// sha1加密字符串,并返回圈小写
        /// </summary>
        /// <param name="strEncryption"></param>
        /// <returns></returns>
        public static string StrSha1Lower(string strEncryption)
        {
            Byte[] bytes = System.Text.Encoding.UTF8.GetBytes(strEncryption);
            SHA1CryptoServiceProvider scsp = new SHA1CryptoServiceProvider();

            Byte[] byteTemp = scsp.ComputeHash(bytes);
            scsp.Clear();
            string strRtn = BitConverter.ToString(byteTemp).Replace("-", "").ToLower();

            return(strRtn);
        }
コード例 #11
0
    /// <summary>
    /// 对字符串进行SHA1加密
    /// </summary>
    /// <param name="strIN">需要加密的字符串</param>
    /// <returns>密文</returns>
    public string SHA1Encrypt(string strIN)
    {
        strIN = GetStrIN(strIN);
        byte[] tmpByte;
        SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();

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

        return(GetStringValue(tmpByte));
    }
コード例 #12
0
ファイル: HashFunction.cs プロジェクト: epdumitru/mysqlib
		public static ID GenerateID(IKey key)
		{
			byte[] keyBytes = key.GetBytes();
			ID id;
			using (SHA1 sha1 = new SHA1CryptoServiceProvider())
			{
				id = new ID(sha1.ComputeHash(keyBytes));
				sha1.Clear();
			}
			return id;
		}
コード例 #13
0
        //SHA1加密
        public string GetSHA1(string input)
        {
            var output      = string.Empty;
            var sha1        = new SHA1CryptoServiceProvider();
            var inputBytes  = UTF8Encoding.UTF8.GetBytes(input);
            var outputBytes = sha1.ComputeHash(inputBytes);

            sha1.Clear();
            output = BitConverter.ToString(outputBytes);
            return(output);
        }
コード例 #14
0
        private static string GetSHA1HashData(string data)
        {
            SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();

            byte[] byteV = System.Text.Encoding.UTF8.GetBytes(data);
            byte[] byteH = SHA1.ComputeHash(byteV);

            SHA1.Clear();

            return(Convert.ToBase64String(byteH));
        }
コード例 #15
0
ファイル: HashFunction.cs プロジェクト: epdumitru/mysqlib
		public static ID GenerateID(string s)
		{
			byte[] data = UTF8Encoding.UTF8.GetBytes(s);
			ID id;
			using (SHA1 sha1 = new SHA1CryptoServiceProvider())
			{
				id = new ID(sha1.ComputeHash(data));
				sha1.Clear();
			}
			return id;
		}
コード例 #16
0
        public void ComputeHash()
        {
            UTF8Encoding utf8 = new UTF8Encoding();

            byte[]        textWithSaltBytes = utf8.GetBytes(string.Concat(PlainText, Salt));
            HashAlgorithm hasher            = new SHA1CryptoServiceProvider();

            byte[] hashedBytes = hasher.ComputeHash(textWithSaltBytes);
            hasher.Clear();
            Hash = Convert.ToBase64String(hashedBytes);
        }
コード例 #17
0
        public static string Salt(string salt, string password)
        {
            var sha1 = new SHA1CryptoServiceProvider();

            var byteValue = Encoding.UTF8.GetBytes(salt + password);

            var byteHash = sha1.ComputeHash(byteValue);

            sha1.Clear();

            return(Convert.ToBase64String(byteHash));
        }
コード例 #18
0
        /// <summary>
        /// Encripta una Cadena con el Método Hash
        /// </summary>
        /// <param name="cadena">Cadena a encriptar</param>
        public static string Encriptar(string cadena)
        {
            HashAlgorithm hashValue = new SHA1CryptoServiceProvider();

            byte[] byteValue = Encoding.UTF8.GetBytes(cadena);

            byte[] byteHash = hashValue.ComputeHash(byteValue);

            hashValue.Clear();

            return(Convert.ToBase64String(byteHash));
        }
コード例 #19
0
ファイル: CryptoHelper.cs プロジェクト: U3DC/Team_Open
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string SHA1_Encrypt(string source)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(source);
            SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();

            byte[] value = sHA1CryptoServiceProvider.ComputeHash(bytes);
            sHA1CryptoServiceProvider.Clear();
            string text = BitConverter.ToString(value);

            text = text.Replace("-", "");
            return(text.ToLower());
        }
コード例 #20
0
        /// <summary>
        /// SHA1单向加密数据
        /// </summary>
        public static byte[] SHA1Encrypt(byte[] b)
        {
            if (b == null)
            {
                return(null);
            }
            SHA1 sha1 = new SHA1CryptoServiceProvider();

            b = sha1.ComputeHash(b);
            sha1.Clear();
            return(b);
        }
コード例 #21
0
ファイル: HashEncrypt.cs プロジェクト: zmyz2013/RoadFlowMvc
        public string SHA1Encrypt(string strIN)
        {
            if (strIN.IsNullOrEmpty())
            {
                return(string.Empty);
            }
            SHA1CryptoServiceProvider cryptoServiceProvider = new SHA1CryptoServiceProvider();

            byte[] hash = cryptoServiceProvider.ComputeHash(this.GetKeyByteArray(strIN));
            cryptoServiceProvider.Clear();
            return(this.GetStringValue(hash));
        }
コード例 #22
0
        public static string SHA1EncryptPassword(string password)
        {
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }
            SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();
            string text = BitConverter.ToString(sHA1CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(password)));

            sHA1CryptoServiceProvider.Clear();
            return(text.Replace("-", null));
        }
コード例 #23
0
        private string CalclateSha1(byte[] data)
        {
            // SHA1のプロバイダーを作成
            var sha1 = new SHA1CryptoServiceProvider();
            // ハッシュ値を計算
            var hashedBytes = sha1.ComputeHash(data);

            // リソース開放
            sha1.Clear();
            // ハッシュ値をテキストに戻す
            return(GetTextFromHash(hashedBytes));
        }
コード例 #24
0
    public static string EncryptSHA1(string plainText)
    {
        HashAlgorithm hash = new SHA1CryptoServiceProvider();

        byte[] plainData  = Encoding.UTF8.GetBytes(plainText);
        byte[] cipherData = hash.ComputeHash(plainData);
        hash.Clear();

        string cipherText = Convert.ToBase64String(cipherData);

        return(cipherText);
    }
コード例 #25
0
        public string SHA1Encrypt(string strIN)
        {
            if (strIN.IsNullOrEmpty())
            {
                return(string.Empty);
            }
            SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();

            byte[] @byte = sHA1CryptoServiceProvider.ComputeHash(GetKeyByteArray(strIN));
            sHA1CryptoServiceProvider.Clear();
            return(GetStringValue(@byte));
        }
コード例 #26
0
        /// <summary>
        /// Caculate string's SHA1 value. 计算字符串的SHA1值。
        /// </summary>
        /// <param name="btIN">input Byte Array. 输入的字节数组。</param>
        /// <returns>Return SHA1 value. 返回SHA1值。</returns>
        public static string sha1(byte[] btIN)
        {
            byte[] tmpByte;
            SHA1   sha1 = new SHA1CryptoServiceProvider();

            tmpByte = sha1.ComputeHash(btIN);
            sha1.Clear();
            string strResult = BitConverter.ToString(tmpByte);

            strResult = strResult.Replace("-", "");
            return(strResult);
        }
コード例 #27
0
ファイル: WechatHelper.cs プロジェクト: wturi/JiXiuGe
        /// <summary>
        /// 将现有的字符串进行sha1签名
        /// </summary>
        /// <param name="dstr"></param>
        /// <returns></returns>
        public static string GetSha1(string dstr)
        {
            byte[] tmp = Encoding.UTF8.GetBytes(dstr);

            SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();

            byte[] tmp2 = sha.ComputeHash(tmp);
            sha.Clear();

            string ret = BitConverter.ToString(tmp2).Replace("-", "").ToLower();

            return(ret);
        }
コード例 #28
0
        public static string Hash(string input)
        {
            StringBuilder             hash = new StringBuilder();
            SHA1CryptoServiceProvider SHA1CryptoService = new SHA1CryptoServiceProvider();

            byte[] bytes = SHA1CryptoService.ComputeHash(UTF8Encoding.UTF8.GetBytes(input));
            for (int i = 0; i < bytes.Length; i++)
            {
                hash.Append(bytes[i].ToString("X2"));
            }
            SHA1CryptoService.Clear();
            return(hash.ToString());
        }
コード例 #29
0
        /// <summary>
        ///     计算SHA1的加密值
        /// </summary>
        /// <param name="Input">输入的字符串</param>
        /// <returns></returns>
        public static string SHA1(this string Input)
        {
            if (string.IsNullOrEmpty(Input))
            {
                throw new ArgumentNullException("Input");
            }
            SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();

            byte[] InputArray  = System.Text.Encoding.ASCII.GetBytes(Input);
            byte[] HashedArray = SHA1.ComputeHash(InputArray);
            SHA1.Clear();
            return(BitConverter.ToString(HashedArray).Replace("-", ""));
        }
コード例 #30
0
        public static string SHA1(String data)
        {
            SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();

            Byte[] temp1 = Encoding.UTF8.GetBytes(data);
            Byte[] temp2 = sha.ComputeHash(temp1);

            sha.Clear();

            String output = BitConverter.ToString(temp2).Replace("-", "").ToLower();

            return(output);
        }
コード例 #31
0
    protected void SubmitButton_Click1(object sender, EventArgs e)
    {
        string username = TextBoxUN.Text;
        string password = TextBoxPW.Text + TextBoxUN.Text;
        HashAlgorithm mhash = new SHA1CryptoServiceProvider();
        byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(password);
        byte[] bytHash = mhash.ComputeHash(bytValue);
        mhash.Clear();
        password = Convert.ToBase64String(bytHash);

        string fullname = TextBoxFN.Text;
        string emailid = TextBoxEID.Text;

        String constr = Session["connection"].ToString();
        OdbcConnection cn = new OdbcConnection(constr);
        cn.Open();

        if (IsPostBack)
        {
            Response.Write("You have successfully completed registration");
            string sql = "insert into userdata values ('" + username + "','" + password + "','"+ fullname + "','"+emailid+"');";
            OdbcCommand cmd = new OdbcCommand(sql, cn);

            try
            {
                cmd.ExecuteNonQuery();
            }

            finally
            {
                cn.Close();
                cn.Dispose();

            }

            SubmitButton.Enabled = false;
            Response.Redirect("HomePage.aspx");

        }
    }
コード例 #32
0
ファイル: clsencrypt.cs プロジェクト: parveenxps/Cibus-Web
    //AIM: THIS FUNCTION IS USE to encrypt the string and create hask key using diff hash methods
    public string FromString(string input, HashType hashtype)
    {
        Byte[] clearBytes;
            Byte[] hashedBytes;
            string output = String.Empty;

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

                    sha256.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA384:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA384 sha384 = new SHA384Managed();
                    sha384.ComputeHash(clearBytes);
                    hashedBytes = sha384.Hash;
                    sha384.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
                case HashType.SHA512:
                    clearBytes = Encoding.UTF8.GetBytes(input);
                    SHA512 sha512 = new SHA512Managed();
                    sha512.ComputeHash(clearBytes);
                    hashedBytes = sha512.Hash;
                    sha512.Clear();
                    output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                    break;
            }
            return output;
    }
コード例 #33
0
    protected void LoginButton_Click1(object sender, ImageClickEventArgs e)
    {
        String constr = Session["connection"].ToString();
        OdbcConnection cn = new OdbcConnection(constr);
        cn.Open();
        string username = UNtext.Text;
        String password = PWText.Text + UNtext.Text;
        HashAlgorithm mhash = new SHA1CryptoServiceProvider();
        byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(password);
        byte[] bytHash = mhash.ComputeHash(bytValue);
        mhash.Clear();
        password = Convert.ToBase64String(bytHash);
        string priv = Request.QueryString["query"];
        if (IsPostBack)
        {
            string sql = null;

            if (priv.Equals("user"))
            {
                sql = "select * from userdata where username ='******' and password ='******';";
                Session["user_cust_id"] = username;
            }

            if (priv.Equals("admin"))
            {
                sql = "select * from userdata where username ='******' and password ='******';";
            }
            else
            {

            }

            OdbcCommand cmd = new OdbcCommand(sql, cn);

            try
            {
                OdbcDataReader dr = cmd.ExecuteReader();
                if (priv.Equals("user") && UNtext.ToString().Equals("admin"))
                {
                    Label1.Text = "Failed to authenticate";
                }
                else
                {
                    if (dr.HasRows == true)
                    {

                        if (priv.Equals("admin"))
                        {
                            Session["auth"] = "1";
                        }
                        else
                        {
                            Session["auth"] = "2";
                        }
                        Response.Redirect("HomePage.aspx");
                    }
                    else
                        Label1.Text = "Failed to authenticate";
                }
            }

            finally
            {
                cn.Close();
                cn.Dispose();

            }
        }
    }