using System.Collections.Generic; using System.Security.Cryptography; using System.Text; using XC.Framework.Security.RSAUtil; namespace TEAMModelOS.SDK.Helper.Security.RSACrypt { /// /// RSA加密解密 /// https://github.com/stulzq/RSAUtil /// public class RSACrypt { private readonly RsaPkcs1Util _RsaUtil; private readonly Encoding _encoding; /// /// 获得私钥和公钥 /// [0]=privateKey 私钥 /// [1]=publicKey 公钥 /// /// public static List GetKey() { return RsaKeyGenerator.Pkcs1Key(2048, true); } /// /// 实例化 /// /// 编码类型 /// 私钥 /// 公钥 public RSACrypt(string privateKey, string publicKey) { _encoding = Encoding.UTF8; _RsaUtil = new RsaPkcs1Util(_encoding, publicKey, privateKey, 1024); } /// /// 加密 /// /// 加密代码 /// public string Encrypt(string code) { return _RsaUtil.Encrypt(code, RSAEncryptionPadding.Pkcs1); } /// /// 解密 /// /// 解密代码 /// public string Decrypt(string code) { return _RsaUtil.Decrypt(code, RSAEncryptionPadding.Pkcs1); } } }