using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XC.RSAUtil;

namespace CrazyStudio.Core.Common.CryptHelper
{
    public static class RSACrypt
    {
        private const string PrivateKey = @"-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDSQmInGszCHNC
EsGmsRYdswqlMTGAmzgT71iVP1WNUGSe5GEjQ5g54LObacodKBPzVjerx0MBlne6
IfYE6zfuW6YDrZFAUt7zhcAVwEUzcAG2sH4CLTMdEX8q1PIbPLCB+L+AhhZVEbOS
Djiigbqr7naROpr0pKIpjKRc2IcG1Oib1rfd19cr/knp6V4MCH1XVOci2ttjSl5g
VdpX269Z/+qqtMcJW03DZetyUZk+XKK3ebFti0Bqu7EVRdFAityZI2eKvOOxcrRU
sCIEpfxDgVsX0uIWdHE8huqtYgoQIYfMl8tt22u5FrPZOduWOjNTEp46kwRVYFs2
G75l6aNBAgMBAAECggEAApwGDiJyZhRyvF+Pm22dE/M+yiuS7drq8BiHTDluVsWG
JZbY7RQo98IcoWF2mJD2FANUpdYntYPQNNdWD244etYUT+pFAfiTskdY+6XJb6ni
q/oAUK+tBiyBCvc0NVwOKBuK5y+SC+o7RlFagxxNNriRSfAOoXicQQZsigLjDTIF
qttPrS8/aWiSLhCiSNvOrjbgdTEUgiW9lsZUOQ3p2iRGwvoPkQvbZl5pLBd09Ad8
eTZX5zhiTqszisgcBvqEO6vyLD1i0kv24lHJag9VZc2S5gNar3+QTrwaRT3M5rlw
vNX4Vtawo4XZATdieMIY14MkK4xbhGbQzOu6ReRZEQKBgQD15nFrL+npTiL8+Vaz
VFYBPGA6r/pB1Rq8N4wkaCQfqhb0kn1YCUSublJughcI4QoNvoiXuR3BDS230MEV
HPoIDbT+TOft4mQfO6O6zIckOs20eLXfygVmwiD7IjHlbJ3IJbBkoklxYVdVOpX6
YC83lNTsfKBKRHLkfY6zANdQfQKBgQDLTmViAeBcYzdzgCkdI8dZ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9LiFnRxPIbqrWIKECGHzJfLbdtruRaz2TnbljozUxKeOpMEVWBbNhu+Zemj
QQIDAQAB
-----END PUBLIC KEY-----
";
        public static string Encrypt(string data)
        {
            var rsaUtil = new RsaPkcs8Util(Encoding.UTF8, PublicKey, PrivateKey);
            string encryptData = rsaUtil.Encrypt(data, RSAEncryptionPadding.Pkcs1);
            return encryptData;
        }

        public static string Decrypt(string encryptData)
        {
            var rsaUtil = new RsaPkcs8Util(Encoding.UTF8, PublicKey, PrivateKey);
            string data = rsaUtil.Decrypt(encryptData, RSAEncryptionPadding.Pkcs1);
            return data;
        }
    }
}
