Esempio n. 1
0
        /// <summary>
        /// 加密字符串,输出BASE64编码字符串
        /// </summary>
        /// <param name="source">要加密的明文字符串</param>
        /// <param name="key">密钥字符串,长度为8或者24</param>
        /// <returns>加密的BASE64编码的字符串</returns>
        public static string Encrypt(string source, string key)
        {
            source.CheckNotNull("source");
            key.CheckNotNullOrEmpty("key");
            byte[]    keyBytes = Encoding.UTF8.GetBytes(key);
            DesHelper des      = new DesHelper(keyBytes);

            return(des.Encrypt(source));
        }
        /// <summary>
        /// 加密要发送的数据,包含签名,DES加密,RSA加密DES密钥等步骤
        /// </summary>
        /// <param name="data">要加密的正文明文数据</param>
        /// <returns>已加密待发送的密文</returns>
        public string EncryptData(string data)
        {
            data.CheckNotNull("data");

            //获取正文摘要
            string signData = RsaHelper.SignData(data, _hashType, _ownPrivateKey);

            data = new[] { data, signData }.ExpandAndToString(Separator);
            //使用DES加密 正文+摘要
            DesHelper des = new DesHelper();

            data = des.Encrypt(data);
            //RSA加密DES密钥
            string enDesKey = Convert.ToBase64String(RsaHelper.Encrypt(des.Key, _facePublicKey));

            return(new[] { enDesKey, data }.ExpandAndToString(Separator));
        }
Esempio n. 3
0
        /// <summary>
        /// 加密字节数组
        /// </summary>
        /// <param name="source">要加密的字节数组</param>
        /// <param name="key">密钥字节数组,长度为8或者24</param>
        /// <returns>加密后的字节数组</returns>
        public static byte[] Encrypt(byte[] source, byte[] key)
        {
            DesHelper des = new DesHelper(key);

            return(des.Encrypt(source));
        }
        /// <summary>
        /// 加密要发送的数据,包含签名,DES加密,RSA加密DES密钥等步骤
        /// </summary>
        /// <param name="data">要加密的正文明文数据</param>
        /// <returns>已加密待发送的密文</returns>
        public string EncryptData(string data)
        {
            data.CheckNotNull("data");

            //获取正文摘要
            string signData = RsaHelper.SignData(data, _hashType, _ownPrivateKey);
            data = new[] { data, signData }.ExpandAndToString(Separator);
            //使用DES加密 正文+摘要
            DesHelper des = new DesHelper();
            data = des.Encrypt(data);
            //RSA加密DES密钥
            string enDesKey = Convert.ToBase64String(RsaHelper.Encrypt(des.Key, _facePublicKey));
            return new[] { enDesKey, data }.ExpandAndToString(Separator);
        }
Esempio n. 5
0
 /// <summary>
 /// 加密字符串,输出BASE64编码字符串
 /// </summary>
 /// <param name="source">要加密的明文字符串</param>
 /// <param name="key">密钥字符串,长度为8或者24</param>
 /// <returns>加密的BASE64编码的字符串</returns>
 public static string Encrypt(string source, string key)
 {
     source.CheckNotNull("source");
     key.CheckNotNullOrEmpty("key");
     byte[] keyBytes = Encoding.UTF8.GetBytes(key);
     DesHelper des = new DesHelper(keyBytes);
     return des.Encrypt(source);
 }
Esempio n. 6
0
 /// <summary>
 /// 加密字节数组
 /// </summary>
 /// <param name="source">要加密的字节数组</param>
 /// <param name="key">密钥字节数组,长度为8或者24</param>
 /// <returns>加密后的字节数组</returns>
 public static byte[] Encrypt(byte[] source, byte[] key)
 {
     DesHelper des = new DesHelper(key);
     return des.Encrypt(source);
 }