1 Internal classCcbrsacryptprovider2 {3 Private StaticRSACryptoServiceProvider _providerforsign;4 Private StaticRSACryptoServiceProvider _providerforverifysign;5 Private Static ReadOnly ObjectSignobj =New Object();6 Private Static ReadOnly ObjectVerifysignobj =New Object();7 8 Internal StaticRSACryptoServiceProvider Getinstanceforsign (stringprivatekeyfile)9 {Ten if(NULL! = _providerforsign)return_providerforsign; One Lock(signobj) A { - if(NULL! = _providerforsign)return_providerforsign; - varProvider =NewRSACryptoServiceProvider (); the provider. Fromxmlstring (Getxmlcontent (Privatekeyfile)); -_providerforsign =provider; - } - return_providerforsign; + } - + Internal StaticRSACryptoServiceProvider Getinstanceforverifysign (stringpublickeyfile) A { at if(NULL! = _providerforverifysign)return_providerforverifysign; - Lock(verifysignobj) - { - if(NULL! = _providerforverifysign)return_providerforverifysign; - varProvider =NewRSACryptoServiceProvider (); - provider. Fromxmlstring (Getxmlcontent (Publickeyfile)); in_providerforverifysign =provider; - } to return_providerforverifysign; + } - the Private Static stringGetxmlcontent (stringFilePath) * { $ returnFile.readalltext (filePath);Panax Notoginseng } - the PrivateCcbrsacryptprovider () + { A } the}
A complete class is used to generate the RSACryptoServiceProvider Singleton class (. NET)