using System;
using System.Collections.Generic;
using System.Text;
using ChuPiao.Common.Core.Security;
using ChuPiao.Common.Utils;

namespace ChuPiao.Common.Core.Utils
{
    /// <summary>
    /// 电子票文本工具类
    /// </summary>
    public class TicketTextUtil
    {
        //DES密钥（必须8位）
        private static string _desKey = "gtd!@#$%";
        //DES初始化向量
        private static string _desIV = "wbw^&*()";

        /// <summary>
        /// 压缩并加密电子票
        /// </summary>
        /// <param name="data">电子票byte数组</param>
        /// <returns>压缩并加密后的base64字符串</returns>
        public static string CompressAndEncrypt(byte[] data)
        {
            byte[] arr1 = GZipUtil.Compress(data);
            byte[] arr2 = DesUtil.Encrypt(_desKey,_desIV,arr1);
            return Convert.ToBase64String(arr2);
        }
        /// <summary>
        /// 解密并解压缩
        /// </summary>
        /// <param name="input">压缩并加密后的base64字符串</param>
        /// <returns>电子票byte数组</returns>
        public static byte[] DecryptAndDecompress(string input)
        {
            byte[] arr1 = Convert.FromBase64String(input);
            byte[] arr2 = DesUtil.Decrypt(_desKey, _desIV, arr1);
            return GZipUtil.Decompress(arr2);
        }
    }
}
