如何获得Windows Azure Management API的X509证书?

时间:2015-05-14 12:26:18

标签: c# azure x509certificate azure-management-api

我很难连接到Windows Azure管理API我相信它是因为我没有正确的X509证书信息。

我试图遵循本教程:https://code.msdn.microsoft.com/windowsazure/How-to-create-a-Azure-SQL-5157ce03

我尝试创建自己的自签名证书并将其上传到Azure,然后从证书中复制指纹,但我收到以下错误。

这是我的代码:

public class CreateAzureDatabase {

    protected static string subscriptionId = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}";
    protected static string serverName = "xxxxxxxxxx.database.windows.net";
    public static string base64EncodedCertificate = "xxxxxxxxxxxxxxxxxxxxxxxxxx";

    public void DoDatabase(string newDatabaseName) {

        SqlManagementClient client = new SqlManagementClient(getCredentials());
        //Server Name is your SQL Azure DataBase server name, for example:da0dt6hrt6 
        client.Databases.Create(serverName, new Microsoft.WindowsAzure.Management.Sql.Models.DatabaseCreateParameters() {
            Name = newDatabaseName,
            MaximumDatabaseSizeInGB = 1,
            CollationName = "SQL_Latin1_General_CP1_CI_AS"
        });

        Console.ReadLine(); 
    }
    static SubscriptionCloudCredentials getCredentials() {
        return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
    } 

}

我得到的错误是: CryptographicException

An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll

Additional information: Cannot find the requested object.

为什么会发生此错误?

如何为Azure门户获取正确的base64EncodedCertificate?

0 个答案:

没有答案