コード例 #1
0
ファイル: EncrptionHelper.cs プロジェクト: lo9nhy6/MyHelper
        /// <summary>
        /// 加密方法
        /// </summary>
        /// <param name="str">待加密字符串</param>
        /// <param name="encodeType">编码方式</param>
        /// <returns></returns>
        public static DESEntity MyEncryption(string str, string encodeType)
        {
            //实例化EncryptionHelper
            DESHelper encryptionHelper = new DESHelper(encodeType);

            //为EncryptString加密方法准备参数
            byte[] strArray = StrToBytes(str);
            byte[] keyArray = encryptionHelper.keyArray;
            byte[] ivArray  = encryptionHelper.IVArray;

            //获取加密后的数据流
            byte[] getStream = EncryptString(strArray, keyArray, ivArray);

            //实例化EncrptionEntity对象
            DESEntity encrptionEntity = new DESEntity();

            //为encrptionEntity属性赋值
            encrptionEntity.EncrptedString = BytesArrayToString(getStream);
            encrptionEntity.IVstr          = BytesArrayToString(encryptionHelper.keyArray);
            encrptionEntity.keyStr         = BytesArrayToString(encryptionHelper.IVArray);

            //返回
            return(encrptionEntity);
        }
コード例 #2
0
        /// <summary>
        /// 加密方法
        /// </summary>
        /// <param name="str">待加密字符串</param>
        /// <param name="encodeType">编码方式</param>
        /// <returns></returns>
        public static DESEntity MyEncryption(string str, string encodeType)
        {

            //实例化EncryptionHelper
            DESHelper encryptionHelper = new DESHelper(encodeType);

            //为EncryptString加密方法准备参数
            byte[] strArray = StrToBytes(str);
            byte[] keyArray = encryptionHelper.keyArray;
            byte[] ivArray = encryptionHelper.IVArray;

            //获取加密后的数据流
            byte[] getStream = EncryptString(strArray, keyArray, ivArray);

            //实例化EncrptionEntity对象
            DESEntity encrptionEntity = new DESEntity();

            //为encrptionEntity属性赋值
            encrptionEntity.EncrptedString = BytesArrayToString(getStream);
            encrptionEntity.IVstr = BytesArrayToString(encryptionHelper.keyArray);
            encrptionEntity.keyStr = BytesArrayToString(encryptionHelper.IVArray);

            //返回 
            return encrptionEntity;
        }