Yizhong International-008) [original] use the DOTNET password system to ensure data security
//////////////////////////////////////// /////////////////////
// Author: stardicky //
// E-mail: stardicky@hotmail.com //
// Qqnumber: 9531511 //
// CompanyName: ezone International //
// Class: HBS-0308 //
// Title: Use the DOTNET password system to ensure data security //
//////////////////////////////////////// /////////////////////
// Note: Use the DES symmetric encryption algorithm in one of the DOTNET cryptographic systems to ensure data security //
//////////////////////////////////////// /////////////////////
Using system;
Using system. IO;
Using system. text;
Using system. Security. cryptography;
Namespace ezoneinternationalsecuritycryptography
{
Class ezonesecuritycryptographydemo
{
[Stathread]
Public static void main (string [] ARGs)
{
// Encrypt data (from memory to file)
Ezoneencryptordemo ();
// Decrypt data (from file to memory)
Ezonedecryptordemo ();
}
/// <Summary>
/// Encryption
/// </Summary>
Public static void ezoneencryptordemo ()
{
// Create a file object. The file mode is to create a new file, and the file access permission is writable!
Filestream FS = new filestream ("ezonedemo.txt", filemode. Create, fileaccess. Write );
Console. writeline ("Enter the string you want to encrypt :");
// Enter the string you want to encrypt
String yourinput = console. Readline ();
// Convert a string to a byte
Byte [] yourinputstorage = system. Text. encoding. utf8.getbytes (yourinput );
// Create an encryption class for the DES algorithm
Descryptoserviceprovider myserviceprovider = new descryptoserviceprovider ();
// Create an encryption and conversion interface object from the createencryptor method of the DES algorithm's Encryption Class Object
// The meaning of the first parameter is the secret key of the symmetric algorithm (the length is 64 bits, that is, 8 bytes)
// Either manually input or randomly generated: myserviceprovider. generatekey ();
// The second parameter indicates the initialization vector of the symmetric algorithm (the length is 64 bits, that is, 8 bytes)
// Either manually input or randomly generated: myserviceprovider. generateiv ();
Icryptotransform mytransform = myserviceprovider. createencryptor (New byte [] {100,110,120,130,100,110,120,130}, new byte [] {100,110,120,130,100,110,120,130 });
// The Role Of The cryptostream object is to connect the data stream to the encrypted conversion stream.
Cryptostream mycryptostream = new cryptostream (FS, mytransform, cryptostreammode. Write );
// Write data in the byte array to the encrypted stream
Mycryptostream. Write (yourinputstorage, 0, yourinputstorage. Length );
// Disable the encrypted Stream Object
Mycryptostream. Close ();
}
/// <Summary>
/// Decrypt
/// </Summary>
Public static void ezonedecryptordemo ()
{
Filestream FS = new filestream ("ezonedemo.txt", filemode. Open, fileaccess. Read );
Descryptoserviceprovider myserviceprovider = new descryptoserviceprovider ();
// Create a decryption and conversion interface object from the createencryptor method of the DES algorithm's Encryption Class Object
// [Symmetric algorithm secret key] must be the [symmetric algorithm secret key] during encryption
// [Symmetric algorithm initialization vector] must be the [symmetric algorithm initialization vector] during encryption
// If they are different, an exception is thrown.
Icryptotransform mytransform = myserviceprovider. createdecryptor (New byte [] {100,110,120,130,100,110,120,130}, new byte [] {100,110,120,130,100,110,120,130 });
Cryptostream mycryptostream = new cryptostream (FS, mytransform, cryptostreammode. Read );
Byte [] yourinputstorage = new byte [1000];
Int Len = mycryptostream. Read (yourinputstorage, 0, yourinputstorage. Length );
Console. writeline ("the string you just entered is :");
Console. writeline (system. Text. encoding. utf8.getstring (yourinputstorage, 0, Len ));
}
}
}