In my programming practices. NET Web Form page transmits encrypted string information (such as user name and password) to the ASP page, and then decrypts the encrypted string on this page. If it is not an encrypted string, it can be directly transmitted and received on the ASP page through the GET or POST method, but the problem is. NET Web Form page, how can I decrypt the encrypted string in ASP? This is mainly because ASP cannot directly access managed classes and components provided by. NET. In this case, we can only implement the COM component. Through the COM interoperability, we can generate a COM component through. NET, and then access the COM component on the ASP page.
This document transfers the encrypted user name and password from the. aspx page to the. asp page. The following describes the specific steps for these operations:
1. Create a. NET assembly with encryption and decryption strings (VS. NET Class Library Project)
This Assembly will become a COM component. Using the DES symmetric encryption code, you can add a password, encrypt and decrypt it, and support Chinese characters!
// File name: StringCrypt. cs
Using System;
Using System. Runtime. InteropServices;
Using System. Security. Cryptography;
Using System. IO;
Using System. Text;
Namespace jonson
{
// First create an interface, which is required by Com
[Guid ("BF6F9C17-37FA-4ad9-9601-C11AD5316F2C")]
Public interface IEncrypt
{
String Encrypt (string pToEncrypt, string sKey );
String Decrypt (string pToDecrypt, string sKey );
}
// Interface implementation
[Guid ("3FBDBB63-3C36-4602-89E1-73EDB0F167D0")]
Public class StringCrypt: IEncrypt
{
// Encryption Method
Public string Encrypt (string pToEncrypt, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider ();
// Put the string in the byte array
Byte [] inputByteArray = Encoding. Default. GetBytes (pToEncrypt );
// Byte [] inputByteArray = Encoding. Unicode. GetBytes (pToEncrypt );
// Create the key and offset of the encryption object
// The GetBytes method of the original text using the ASCIIEncoding. ASCII Method
// Make sure that you enter the English text for the password