- 作者:xiaoxiao
- 发表时间:2020-12-23 10:55
- 来源:未知
HashPasswordForStoringInConfigFile方法来解决问题。这样做的目的是加密配置文件的口令,甚至cookies.HashPasswordForStoringInConfigFile方法非常容易使用,并且,它支持“SHA1”和“MD5”散列算法。为了清楚“HashPasswordForStoringInConfigFile”方法,让我们制作一个小的ASP.NET页,把输入串在SHA1和MD5格式 中译成密码。now go <%@ Import Namespace="System.Web.Security" %><html><head><script language="VB" runat=server>Sub encryptString(Src As Object, E As EventArgs)SHA1.Text = CookieAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1")MD5.Text = CookieAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5")End Sub</script></head><body> <form runat=server> <p><b>Original Clear Text Password: </b><br><asp:Textbox id="txtPassword" runat=server /><asp:Button runat="server" text="Encrypt String" onClick="encryptString" /></p> <p><b>Encrypted Password In SHA1: </b><asp:label id="SHA1" runat=server /></p> <p><b>Encrypted Password In MD5: </b><asp:label id="MD5" runat=server /></p> </form> </body> </html> 怎么样加密一串字符串是很容易的事,为了使它更容易使用我制作了一个函数。下面我就给出函数的源代码. Function EncryptPassword (PasswordString as String, PasswordFormat as String) as String If PasswordFormat = "SHA1" thenEncryptPassword = CookieAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "SHA1")Elseif PasswordFormat = "MD5" thenEncryptPassword= CookieAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "MD5")ElseEncryptPassword = ""End ifEnd Function |