zoukankan      html  css  js  c++  java
  • 一个完整的类用来生成RSACryptoServiceProvider单例类(.NET)

     1 internal class CcbRsaCryptProvider
     2 {
     3         private static RSACryptoServiceProvider _providerForSign;
     4         private static RSACryptoServiceProvider _providerForVerifySign;
     5         private static readonly object SignObj = new object();
     6         private static readonly object VerifySignObj = new object();
     7 
     8         internal static RSACryptoServiceProvider GetInstanceForSign(string privateKeyFile)
     9         {
    10             if (null != _providerForSign) return _providerForSign;
    11             lock (SignObj)
    12             {
    13                 if (null != _providerForSign) return _providerForSign;
    14                 var provider = new RSACryptoServiceProvider();
    15                 provider.FromXmlString(GetXmlContent(privateKeyFile));
    16                 _providerForSign = provider;
    17             }
    18             return _providerForSign;
    19         }
    20 
    21         internal static RSACryptoServiceProvider GetInstanceForVerifySign(string publicKeyFile)
    22         {
    23             if (null != _providerForVerifySign) return _providerForVerifySign;
    24             lock (VerifySignObj)
    25             {
    26                 if (null != _providerForVerifySign) return _providerForVerifySign;
    27                 var provider = new RSACryptoServiceProvider();
    28                 provider.FromXmlString(GetXmlContent(publicKeyFile));
    29                 _providerForVerifySign = provider;
    30             }
    31             return _providerForVerifySign;
    32         }
    33 
    34         private static string GetXmlContent(string filePath)
    35         {
    36             return File.ReadAllText(filePath);
    37         }
    38 
    39         private CcbRsaCryptProvider()
    40         {
    41         }
    42     }
  • 相关阅读:
    Shell 数组
    Shell 中的中括号用法总结
    设置Linux可以查看历史命令(history)的执行时间
    jasypt 对 配置文件密码进行加密处理
    今日进度
    今日进度
    今日进度
    今日进度
    今日进度
    每周总结
  • 原文地址:https://www.cnblogs.com/frankyou/p/4663910.html
Copyright © 2011-2022 走看看