Encrypt value in Javascript & decrypt in serverside(C#)
I am redirecting to serverside from clientSideI want to encrypt the querystring passed from clientSide & decrypt it in server side
public static bool ValidateQueryString(string password, string saltedHash) {
// Extract hash and salt string
string saltString = saltedHash.Substring((saltedHash.Length - 24));
string hash1 = saltedHash.Substring(0, (saltedHash.Length - 24));
// Append the salt string to the password
string saltedPassword = (password + saltString);
// Hash the salted password
string hash2 = FormsAuthentication.HashPasswordForStoringInConfigFile(saltedPassword, "SHA1");
// Compare the hashes
return (hash1.CompareTo(hash2) == 0);
}
<%@ 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>