Nessun risultato. Prova con un altro termine.
Guide
Notizie
Software
Tutorial

Criptare una stringa

<%@ Page Language="C#" %>
<%@ import Namespace="System.Security.Cryptography" %>
<script runat="server">

private string GetMd5String(string strPassword) {
Encoder encoder = System.Text.Encoding.Unicode.GetEncoder();
byte[] unicodeText = new byte[strPassword.Length * 2];
encoder.GetBytes(strPassword.ToCharArray(), 0, strPassword.Length, unicodeText, 0, true);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] pwdCript = md5.ComputeHash(unicodeText);
StringBuilder sb = new StringBuilder();
for ( int i=0; i < pwdCript.Length; i++ ) {
sb.Append(pwdCript.ToString());
}
return sb.ToString();
}

void Button1_Click(Object sender, EventArgs e) {
litTesto.Text = (string) GetMd5String(txtPassword.Text);
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="txtPassword" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
<br />
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Campo obbligatorio!" Display="Dynamic" ControlToValidate="txtPassword"></asp:RequiredFieldValidator>
</p>
<p>
<asp:Literal id="litTesto" runat="server"></asp:Literal>
</p>
<!-- Insert content here -->
</form>
</body>
</html>

<%@ Page Language="C#" %>
<%@ import Namespace="System.Security.Cryptography" %>
<script runat="server">

private string GetMd5String(string strPassword) {
Encoder encoder = System.Text.Encoding.Unicode.GetEncoder();
byte[] unicodeText = new byte[strPassword.Length * 2];
encoder.GetBytes(strPassword.ToCharArray(), 0, strPassword.Length, unicodeText, 0, true);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] pwdCript = md5.ComputeHash(unicodeText);
StringBuilder sb = new StringBuilder();
for ( int i=0; i < pwdCript.Length; i++ ) {
sb.Append(pwdCript.ToString());
}
return sb.ToString();
}

void Button1_Click(Object sender, EventArgs e) {
litTesto.Text = (string) GetMd5String(txtPassword.Text);
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="txtPassword" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
<br />
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Campo obbligatorio!" Display="Dynamic" ControlToValidate="txtPassword"></asp:RequiredFieldValidator>
</p>
<p>
<asp:Literal id="litTesto" runat="server"></asp:Literal>
</p>
<!-- Insert content here -->
</form>
</body>
</html>

Link copiato negli appunti

<%@ Page Language="C#" %>

<%@ import Namespace="System.Security.Cryptography" %>

<script runat="server">

private string GetMd5String(string strPassword) {

Encoder encoder = System.Text.Encoding.Unicode.GetEncoder();

byte[] unicodeText = new byte[strPassword.Length * 2];

encoder.GetBytes(strPassword.ToCharArray(), 0, strPassword.Length, unicodeText, 0, true);

MD5 md5 = new MD5CryptoServiceProvider();

byte[] pwdCript = md5.ComputeHash(unicodeText);

StringBuilder sb = new StringBuilder();

for ( int i=0; i < pwdCript.Length; i++ ) {

sb.Append(pwdCript.ToString());

}

return sb.ToString();

}

void Button1_Click(Object sender, EventArgs e) {

litTesto.Text = (string) GetMd5String(txtPassword.Text);

}

</script>

<html>

<head>

</head>

<body>

<form runat="server">

<p>

<asp:TextBox id="txtPassword" runat="server"></asp:TextBox>

<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>

<br />

<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Campo obbligatorio!" Display="Dynamic" ControlToValidate="txtPassword"></asp:RequiredFieldValidator>

</p>

<p>

<asp:Literal id="litTesto" runat="server"></asp:Literal>

</p>

<!-- Insert content here -->

</form>

</body>

</html>