
using Org.BouncyCastle.Utilities.Encoders;
using SM2Crypto.Lib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace PTMedicalInsurance.Common.SMLib
{
    /// <summary>
    /// 一码付加解密封装
    /// </summary>
    internal class OneCodePayEncryptUtil
    {
        public static String encrypt(String data,  String secKey)
        {
            //secKey是 ASCII 字符串 使用 —— 这是很多国密对接系统的常见做法，将其转换为 16 字节密钥（因为字符串长 16）
            byte[] keyBytes = Encoding.UTF8.GetBytes(secKey);
            //加密0数据
            String encryptDataStr = Hex.ToHexString(EasyGmUtils.sm4Encrypt(keyBytes, Encoding.UTF8.GetBytes(data))).ToUpper();
            return encryptDataStr;
        }

        public static String decrypt(String data, String secKey)
        {
            byte[] keyBytes = Encoding.UTF8.GetBytes(secKey);
            String decryptDataStr = Encoding.UTF8.GetString(EasyGmUtils.sm4Decrypt(keyBytes, Hex.Decode(data)));
            return decryptDataStr;
        }
    }
}
