PassportIdentity.Decrypt
PassportIdentity.Decrypt
Decrypts data encrypted with Encrypt method, using the same key.
Syntax
public static string Decrypt( string strData )
Parameters
- strData
The data to be decrypted.
Return values
Data decrypted using the key for the current site.
Example
The following C# example shows the Compress, Encrypt, Decrypt, and Decompress methods can be used together for transmittal of an encrypted string over a network. In this example, a string is compressed, encrypted, decrypted, and finally decompressed. The displayed string is the same as the original string.
<%@ Page Language="C#"%> <%@ Import Namespace = "System.Web.Security" %> <HTML> <HEAD><TITLE>Mysample - Exercise - CS</TITLE></HEAD> <Script language="C#" runat="server"> string sServer; string sthisURL; protected void Page_Load(Object src, EventArgs e) { sServer = Request.ServerVariables["SERVER_NAME"]; sthisURL = "https://" + sServer + Request.ServerVariables["SCRIPT_NAME"]; } </Script> <% //Instantiate a PassportIdentity object. PassportIdentity oMgr = (PassportIdentity)User.Identity; //LogoTag2 allows the user to sign in or out. Response.Write ("<DIV STYLE = 'position:absolute; right:50px'>" + oMgr.LogoTag2(sthisURL,3600,true,null,1033,false,null,-1,false) + "</DIV>"); if (oMgr.GetIsAuthenticated(3600,false,false)) { //Define and display the original string string mystring = "This is a string to be compressed, encrypted, transmitted, decrypted, and finally decompressed."; Response.Write ("<br>Original string: " + mystring); //Compress and encrypt the string mystring = PassportIdentity.Compress(mystring); mystring = PassportIdentity.Encrypt(mystring); // //This is where the encrypted string would be transmitted over the wire. // //Decrypt, decompress, and display the string. mystring = PassportIdentity.Decrypt(mystring); mystring = PassportIdentity.Decompress(mystring); Response.Write ("<br>Reconstructed string: " + mystring); } else { Response.Write("<br>You are not authenticated. Please click Sign In or exit the page."); } %>
The preceding example results in a page that looks similar to the following:
Original string: This is a string to be compressed, encrypted, transmitted, decrypted, and finally decompressed. Reconstructed string: This is a string to be compressed, encrypted, transmitted, decrypted, and finally decompressed.
Remarks
After the Encrypt method is executed, the Decrypt method must be used to make the data readable. The Encrypt and Decrypt methods are used to help ensure the data's security.
Note An empty (NULL) input returns a NULL. Attempting to decrypt a blob larger than 5498 bytes will fail. However, the Encrypt method is limited to a blob size of 2045 bytes and will also fail if attempting to encrypt that amount of data.
See Also
Passport PassportIdentity Object | PassportIdentity.Compress | PassportIdentity.Decompress | PassportIdentity.Encrypt