Using System; Using System. text; Using System. Security. cryptography; Using System. IO; // Default key vector Private Static Byte [] Keys = { 0x12 , 0x34 ,0x56 , 0x78 , 0x90 , 0xab , 0xcd , 0xef }; /// <Summary> /// DES encrypted string /// </Summary> /// <Param name = "encryptstring"> String to be encrypted </Param> /// <Param name = "encryptkey"> Encryption key, which must be 8 bits </Param> /// <Returns> The encrypted string is returned successfully. If the encrypted string fails, the source string is returned. </Returns> Public Static String Encryptdes ( String Encryptstring, String Encryptkey ){ Try { Byte [] Rgbkey = encoding. utf8.getbytes (encryptkey. substring ( 0 , 8 )); Byte [] Rgbiv = Keys; Byte [] Inputbytearray = Encoding. utf8.getbytes (encryptstring); descryptoserviceprovider dcsp = New Descryptoserviceprovider (); memorystream mstream = New Memorystream (); cryptostream cstream = New Cryptostream (mstream, dcsp. createencryptor (rgbkey, rgbiv), cryptostreammode. Write); cstream. Write (inputbytearray, 0 , Inputbytearray. Length); cstream. flushfinalblock (); Return Convert. tobase64string (mstream. toarray ());} Catch { Return Encryptstring ;}} /// <Summary> /// Des decryption string /// </Summary> /// <Param name = "decryptstring"> String to be decrypted </Param> /// <Param name = "decryptkey"> Decryption key, which must be 8 bits, the same as the encryption key </Param> /// <Returns> The decrypted string is returned successfully, and the source string fails to be returned. </Returns> Public Static String Decryptdes ( String Decryptstring, String Decryptkey ){ Try { Byte [] Rgbkey =Encoding. utf8.getbytes (decryptkey ); Byte [] Rgbiv = Keys; Byte [] Inputbytearray = Convert. frombase64string (decryptstring); descryptoserviceprovider dcsp = New Descryptoserviceprovider (); memorystream mstream = New Memorystream (); cryptostream cstream = New Cryptostream (mstream, dcsp. createdecryptor (rgbkey, rgbiv), cryptostreammode. Write); cstream. Write (inputbytearray, 0 , Inputbytearray. Length); cstream. flushfinalblock (); Return Encoding. utf8.getstring (mstream. toarray ());} Catch { Return Decryptstring ;}}