A senior asked me the day before yesterday, on the web. in config, how do I configure the database connection? I mean, according to my normal connection method, data source = .; initial catalog = database; User ID =; Password =; this is the worst method for setting clear codes. I am so sorry, I am so embarrassed to think about it. Then I searched the internet to find out how to set security. We know that people use security algorithms, such as RSA asymmetric encryption algorithms and DES encryption functions. Let's record the next point.
The specific content is as follows:
The encrypted connection string is placed in Web. config. Example code of encryption and decryption:
Asymmetric encryption:
Using System;
Using System. IO;
Using System. Text;
Using System. Security. Cryptography;
/// <Summary>
/// A simple example of using the. NET asymmetric encryption algorithm
/// The program in this example is very simple. It is only used to explain how to use the asymmetric (RSA) algorithm in. NET.
/// </Summary>
Class Class1
{
Public static void Main (string [] args)
{
Class1 c = new Class1 ();
C. StartDemo ();
}
Public void StartDemo ()
{
// RSA encryption and decryption process:
// There are two RSA objects: rsa1 and rsa2.
// If you want rsa2 to send a piece of information to rsa1, rsa1 first sends the "Public Key" to rsa2
// The Public Key obtained by rsa2 is used to encrypt the data to be sent.
// After obtaining the encrypted content, rsa1 decrypts it with its own private key to obtain the original data content.
Rsacryptoserviceprovider rsa1 = new rsacryptoserviceprovider ();
Rsacryptoserviceprovider rsa2 = new rsacryptoserviceprovider ();
String publickey;
Publickey = rsa1.toxmlstring (false); // export the public key of rsa1
String plaintext;
Plaintext = "how are you? This is the string used for testing. "; // Raw data
Console. writeline ("raw data is \ n {0} \ n", plaintext );
Rsa2.fromxmlstring (publickey); // rsa2 imports the public key of rsa1 for information encryption.
// Start rsa2 Encryption
Byte [] cipherbytes;
Cipherbytes = rsa2.encrypt (
Encoding. utf8.getbytes (plaintext ),
False );
Console. writeline ("the encrypted data is :");
For (INT I = 0; I <cipherbytes. length; I ++)
{
Console. Write ("{0: X2}", cipherbytes [I]);
}
Console. writeline ("\ n ");
// Start decryption with rsa1
Byte [] plaintbytes;
Plaintbytes = rsa1.decrypt (cipherbytes, false );
Console. writeline ("the decrypted data is :");
Console. writeline (encoding. utf8.getstring (plaintbytes ));
Console. Readline ();
}
}
This is one of the RSA encryption algorithms. I used the MD5 encryption method in my previous project to verify the user's identity and account. Can I connect to the database using this method?