Exemplo n.º 1
0
        public static string Encrypt(string strText, string encryptKey)
        {
            if (string.IsNullOrEmpty(strText))
            {
                return(strText);
            }
            DESCryptoServiceProvider dESCryptoServiceProvider = DESEncryptor.CreateDESProvider(encryptKey);

            byte[]       bytes        = Encoding.UTF8.GetBytes(strText);
            MemoryStream memoryStream = new MemoryStream();
            CryptoStream cryptoStream = new CryptoStream(memoryStream, dESCryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write);

            cryptoStream.Write(bytes, 0, bytes.Length);
            cryptoStream.FlushFinalBlock();
            return(Convert.ToBase64String(memoryStream.ToArray()));
        }
Exemplo n.º 2
0
        public static string Decrypt(string encryptedText, string decryptKey)
        {
            if (string.IsNullOrEmpty(encryptedText))
            {
                return(encryptedText);
            }
            DESCryptoServiceProvider dESCryptoServiceProvider = DESEncryptor.CreateDESProvider(decryptKey);

            byte[]       array        = Convert.FromBase64String(encryptedText);
            MemoryStream memoryStream = new MemoryStream();
            CryptoStream cryptoStream = new CryptoStream(memoryStream, dESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);

            cryptoStream.Write(array, 0, array.Length);
            cryptoStream.FlushFinalBlock();
            return(new UTF8Encoding().GetString(memoryStream.ToArray()));
        }
Exemplo n.º 3
0
        public static void DecryptFile(string inputFilePath, string outFilePath, string decryptKey)
        {
            FileStream   fileStream   = null;
            FileStream   fileStream2  = null;
            CryptoStream cryptoStream = null;

            try
            {
                fileStream  = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read);
                fileStream2 = new FileStream(outFilePath, FileMode.OpenOrCreate, FileAccess.Write);
                fileStream2.SetLength(0L);
                byte[] buffer = new byte[100];
                long   num    = 0L;
                long   length = fileStream.Length;
                DES    dES    = DESEncryptor.CreateDESProvider(decryptKey);
                cryptoStream = new CryptoStream(fileStream2, dES.CreateDecryptor(), CryptoStreamMode.Write);
                while (num < length)
                {
                    int num2 = fileStream.Read(buffer, 0, 100);
                    cryptoStream.Write(buffer, 0, num2);
                    num += (long)num2;
                }
            }
            finally
            {
                if (cryptoStream != null)
                {
                    cryptoStream.Close();
                }
                if (fileStream2 != null)
                {
                    fileStream2.Close();
                }
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
        }
Exemplo n.º 4
0
 public static string Decrypt(string encryptedText)
 {
     return(DESEncryptor.Decrypt(encryptedText, "auto@#$&"));
 }
Exemplo n.º 5
0
 public static string Encrypt(string strText)
 {
     return(DESEncryptor.Encrypt(strText, "auto@#$&"));
 }
Exemplo n.º 6
0
 public static string MD5Hash(string strText)
 {
     return(DESEncryptor.MD5Hash(strText, Encoding.Default));
 }
Exemplo n.º 7
0
 public static void DecryptFile(string inputFilePath, string outFilePath)
 {
     DESEncryptor.DecryptFile(inputFilePath, outFilePath, "auto@#$&");
 }