Пример #1
0
 public static string DecryptRSAByPfx(string src, string path, string passwd)
 {
     try
     {
         if (String.IsNullOrEmpty(src))
         {
             throw new Exception("加密值为空[src]");
         }
         byte[] StrSrc    = System.Text.Encoding.GetEncoding("GBK").GetBytes(src);
         byte[] Base64Str = Base64.Decode(StrSrc);
         AsymmetricKeyParameter PrivteKey = RsaReadUtil.getPrivateKeyFromFile(path, passwd);//读取私钥
         byte[] DecryString = RSAEDCore(Base64Str, PrivteKey, false);
         return(System.Text.Encoding.Default.GetString(DecryString));
     }
     catch (Exception e) {
         e.GetBaseException();
         throw new Exception("异常:" + e.Message);
     }
 }
Пример #2
0
 public static string EncryptRSAByCer(string src, string path)
 {
     try
     {
         if (String.IsNullOrEmpty(src))
         {
             throw new Exception("加密值为空[src]");
         }
         AsymmetricKeyParameter PublicKey = RsaReadUtil.getPublicKeyFromFile(path); //读取公钥
         byte[] StrSrc  = System.Text.Encoding.GetEncoding("GBK").GetBytes(src);
         byte[] EncrStr = RSAEDCore(StrSrc, PublicKey, true);                       //加密
         //byte[] HEX = System.Text.Encoding.GetEncoding("GBK").GetBytes(Hex.ToHexString(EncrStr));//加密并转成十六进制
         byte[] Base64Str = Base64.Encode(EncrStr);                                 //编码
         return(System.Text.Encoding.Default.GetString(Base64Str));
     }
     catch (Exception e) {
         e.GetBaseException();
         throw new Exception("异常:" + e.Message);
     }
 }