码迷,mamicode.com
首页 > Web开发 > 详细

一个完整的类用来生成RSACryptoServiceProvider单例类(.NET)

时间:2015-07-21 12:29:27      阅读:361      评论:0      收藏:0      [点我收藏+]

标签:

 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     }

 

一个完整的类用来生成RSACryptoServiceProvider单例类(.NET)

标签:

原文地址:http://www.cnblogs.com/frankyou/p/4663910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!