<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Text" %>
<script language="VB" runat="server">
Sub DisplayEncryptedText(sender as Object, e as EventArgs)
If Page.IsValid then
Dim md5Hasher as New MD5CryptoServiceProvider()
Dim hashedDataBytes as Byte()
Dim encoder as New UTF8Encoding()
hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(txtPassword.Text))
ltlResults.Text = "<b>Encrypted Results</b><br /> The results are encrypted into " & _
"an array of 16 bytes. These 16 bytes contain the values:<p><ul>"
Dim b as Byte
For Each b in hashedDataBytes
ltlResults.Text &= "<li>" & b & "</li>"
Next b
ltlResults.Text &= "</ul>"
End If
End Sub
</script>
<form runat="server">
Enter a string:
<asp:TextBox id="txtPassword" runat="server" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtPassword"
Display="Dynamic" ErrorMessage="<i>You must provide a value here...</i>" />
<asp:RegularExpressionValidator runat="server" ControlToValidate="txtPassword"
Display="Dynamic" ErrorMessage="<i>The string must be 20 characters or less...</i>"
ValidationExpression="^.{1,20}$" />
<br />
<asp:Button runat="server" Text="View the String as Encrypted Text"
OnClick="DisplayEncryptedText" />
<p>
<asp:Literal runat="server" id="ltlResults" />
</form>
|