我有这个代码,用于以编程方式在 Azure 中创建数据库,来自这里:
public static string subscriptionId = "ec19938f-6348-4182-83cf-091370e65";
public static string base64EncodedCertificate = "???"; // what goes here?
static SubscriptionCloudCredentials getCredentials()
{
return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
}
static void Main(string[] args)
{
SqlManagementClient client = new SqlManagementClient(getCredentials());
client.Databases.Create("mysub1", new Microsoft.WindowsAzure.Management.Sql.Models.DatabaseCreateParameters()
{
Name = "newdbtest",
MaximumDatabaseSizeInGB = 1,
CollationName = "SQL_Latin1_General_CP1_CI_AS",
Edition = "Web"
});
Console.ReadLine();
}
我相信下一步是获取证书,并将其上传到 Azure。从这个链接,
$cert = New-SelfSignedCertificate -DnsName yourdomain.cloudapp.net -CertStoreLocation "cert:\LocalMachine\My"
$password = ConvertTo-SecureString -String "your-password" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath ".\my-cert-file.pfx" -Password $password
现在我有了证书,我如何获得价值base64EncodedCertificate
?
问题的第二部分:我如何处理 .cer 文件?即我假设我将它上传到 Azure。我必须创建“云服务”吗?