<Certificates>
<Certificate name="MyRandomName" storeLocation="LocalMachine" storeName="My" />
</Certificates>
当我在ServiceDefinition.csdef中有上述内容时。这是证书在服务器上获得的名称“MyRandomName”吗?
如何在OnStart调用中获取它的X509Certificate2实例?是否需要我有一个设置也告诉指纹要查找它?
答案 0 :(得分:0)
我找到了解决问题的另一种方法:
我可以解密这样的设置:
var encryptedBytes = Convert.FromBase64String(setting);
var envelope = new EnvelopedCms();
envelope.Decode(encryptedBytes);
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
envelope.Decrypt(store.Certificates);
string passwordChars = Encoding.UTF8.GetString(envelope.ContentInfo.Content);
当加密像这样:
X509Certificate2 cert = LoadCertificate(
System.Security.Cryptography.X509Certificates.StoreName.My,
System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser, args[0]);
byte[] encoded = System.Text.UTF8Encoding.UTF8.GetBytes(args[1]);
var content = new ContentInfo(encoded);
var env = new EnvelopedCms(content);
env.Encrypt(new CmsRecipient(cert));
string encrypted64 = Convert.ToBase64String(env.Encode());
这意味着用户不必添加
以外的任何指纹<Certificates>
<Certificate name="Composite.WindowsAzure.Management" thumbprint="3D3275357F9DADDDF31F7597656B42137BBBCD56" thumbprintAlgorithm="sha1" />
</Certificates>
在cscfg中为其Cloud Service提供服务,并将其上传到门户网站上。
args [0]和args [1]只是要使用的证书和设置值加密的指纹。