예제 #1
0
파일: AesUtil.cs 프로젝트: bill1411/mybase
        /// <summary>
        /// 解密字符串
        /// </summary>
        /// <param name="encodeInfo">最终加密后的数据(含加密串和IV串的混合串)</param>
        /// <returns>解密后的数据</returns>
        public static string GetDeCodeInfo(string decodeInfo)
        {
            CryptLib _crypt = new CryptLib();
            //aesKey密钥
            string aesKey = System.Configuration.ConfigurationManager.AppSettings["aesKey"].ToString();

            if (!string.IsNullOrWhiteSpace(aesKey))
            {
                //得到hash后的aseKey
                aesKey = CryptLib.getHashSha256(aesKey, 31); //32 bytes = 256 bits
            }
            //返回解密后的原串值
            return(_crypt.decrypt(decodeInfo, aesKey, 16));
        }
예제 #2
0
파일: AesUtil.cs 프로젝트: bill1411/mybase
        /// <summary>
        /// 加密字符串(aesKey)
        /// </summary>
        /// <param name="encodeInfo">要加密的字符串</param>
        /// <returns>加密后的字符串(含IV向量)</returns>
        public static string GetEnCodeInfo(string encodeInfo)
        {
            CryptLib _crypt = new CryptLib();
            string   result = "";
            //aesKey密钥
            string aesKey = System.Configuration.ConfigurationManager.AppSettings["aesKey"].ToString();

            //拿到hash后的aseKey
            aesKey = CryptLib.getHashSha256(aesKey, 31); //32 bytes = 256 bits
            //获取一个16位的随机向量
            string iv = CryptLib.GenerateRandomIV(16);

            //加密字符串(AppID,hashaesKey,iv)
            result = _crypt.encrypt(encodeInfo, aesKey, iv);

            //将加密后的字符串与加密前的IV向量穿插混合后得到最后的串
            return(_crypt.appendIVString(result, iv));  //将加密字符串和iv混合处理后再发送
        }