Code
Public Class Encryptdecrypt
{
Public Static String Encryptstring ( String MES, String Key)
{
Byte [] Inputbytes = Asciiencoding. utf8.getbytes (MES );
Memorystream outputstream = New Memorystream ();
Descryptoserviceprovider des = New Descryptoserviceprovider ();
Des. Key = Asciiencoding. ASCII. getbytes (key );
Des. iv = Asciiencoding. ASCII. getbytes (key );
Icryptotransform desencrypt = Des. createencryptor ();
Cryptostream = New Cryptostream (outputstream, desencrypt, cryptostreammode. Write );
Cryptostream. Write (inputbytes, 0 , Inputbytes. Length );
Cryptostream. flushfinalblock ();
Cryptostream. Close ();
string outputstring = convert. tobase64string (outputstream. toarray ();
return outputstring;
}
Public Static StringDecryptstring (StringMES,StringKey)
{
Byte[] Inputbytes=Convert. frombase64string (MES );
Memorystream outputstream= New Memorystream ();
Descryptoserviceprovider des = New Descryptoserviceprovider ();
Des. Key = Asciiencoding. ASCII. getbytes (key );
Des. iv = Asciiencoding. ASCII. getbytes (key );
Icryptotransform desencrypt = Des. createdecryptor ();
Cryptostream = New Cryptostream (outputstream, desencrypt, cryptostreammode. Write );
Cryptostream. Write (inputbytes, 0 , Inputbytes. Length );
Cryptostream. flushfinalblock ();
Cryptostream. Close ();
StringOutputstring=Asciiencoding. utf8.getstring (outputstream. toarray ());
ReturnOutputstring;
}
}