Пример #1
0
 public string DesEncrypt(string strPlain, string strKey)
 {
     try
     {
         CDES   des         = new CDES();
         byte[] key         = Encoding.UTF8.GetBytes(strKey);
         byte[] plainArray  = Encoding.UTF8.GetBytes(strPlain);
         byte[] cipherArray = des.Encrypt(plainArray, 0, plainArray.Length, key);
         //return Encoding.UTF8.GetString(cipherArray);
         return(Convert.ToBase64String(cipherArray));
     }
     catch (Exception e)
     {
         CPublic.WriteLog("DES 加密过程异常:" + e.Message);
         return(null);
     }
 }
Пример #2
0
 public string DesDecrypt(string strCipher, string strKey)
 {
     try
     {
         CDES   des         = new CDES();
         byte[] key         = Encoding.UTF8.GetBytes(strKey);
         byte[] cipherArray = Convert.FromBase64String(strCipher);
         //byte[] cipherArray = Encoding.UTF8.GetBytes(strCipher);
         byte[] plainArray = des.Decrypt(cipherArray, 0, cipherArray.Length, key);
         return(Encoding.UTF8.GetString(plainArray));
     }
     catch (Exception e)
     {
         CPublic.WriteLog("DES 解密过程异常:" + e.Message);
         return(null);
     }
 }