Calling. NET component programming from COM

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.