Example #1
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="toEncryptString">待加密字符串</param>
        /// <param name="publicKey">公钥</param>
        /// <returns></returns>
        public static string Encrypt(string toEncryptString, byte[] publicKey)
        {
            var dataToEncrypt = Encoding.UTF8.GetBytes(toEncryptString);
            var data          = Encrypt(dataToEncrypt, publicKey);

            return(FormatConvertor.ToHexString(data));
        }
Example #2
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="toEncryptString">待加密字符串</param>
        /// <param name="publicKey">公钥</param>
        /// <returns></returns>
        public static string Encrypt(string toEncryptString, string publicKey)
        {
            var dataToEncrypt = Encoding.UTF8.GetBytes(toEncryptString);
            var keyData       = ConvertToBlob(publicKey, false);
            var data          = Encrypt(dataToEncrypt, keyData);

            return(FormatConvertor.ToHexString(data));
        }
Example #3
0
 public static string Encrypt(System.IO.Stream inputStream)
 {
     using (var md5 = new MD5CryptoServiceProvider())
     {
         byte[] outputData = md5.ComputeHash(inputStream);
         string result     = FormatConvertor.ToHexString(outputData);
         return(result);
     }
 }
Example #4
0
 public static string Encrypt(string text)
 {
     using (var md5 = new MD5CryptoServiceProvider())
     {
         byte[] inputData  = Encoding.UTF8.GetBytes(text);
         byte[] outputData = md5.ComputeHash(inputData);
         string result     = FormatConvertor.ToHexString(outputData);
         return(result);
     }
 }
Example #5
0
 private static string SHA(string text, HashAlgorithm sha)
 {
     using (sha)
     {
         //将mystr转换成byte[]
         byte[] dataToHash = Encoding.UTF8.GetBytes(text);
         //Hash运算
         byte[] dataHashed = sha.ComputeHash(dataToHash);
         //将运算结果转换成string
         return(FormatConvertor.ToHexString(dataHashed));
     }
 }
Example #6
0
 public static string Encrypt(string toEncrypt, string key = "")
 {
     if (string.IsNullOrEmpty(toEncrypt))
     {
         return(string.Empty);
     }
     byte[] keyArray       = string.IsNullOrEmpty(key) ? defaultKey : Encoding.UTF8.GetBytes(key);
     byte[] toEncryptArray = Encoding.UTF8.GetBytes(toEncrypt);
     using (RijndaelManaged rDel = new RijndaelManaged())
     {
         using (ICryptoTransform cTransform = rDel.CreateEncryptor(keyArray, defaultIV))
         {
             byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
             return(FormatConvertor.ToHexString(resultArray));
         }
     }
 }
Example #7
0
 public static string Encrypt(string sInputString, string sKey = "")
 {
     if (string.IsNullOrEmpty(sInputString))
     {
         return(string.Empty);
     }
     using (DESCryptoServiceProvider DES = new DESCryptoServiceProvider())
     {
         byte[] data   = Encoding.UTF8.GetBytes(sInputString);
         byte[] key_iv = GetKeyBytes(sKey);
         DES.Key = key_iv;
         DES.IV  = key_iv;
         using (ICryptoTransform desencrypt = DES.CreateEncryptor())
         {
             byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length);
             return(FormatConvertor.ToHexString(result));
         }
     }
 }