如何从Azure ACS获取对称密钥?

时间:2013-11-13 20:28:26

标签: azure acs

我在使用ACS Management API和对称密钥时遇到了一些问题。当我通过API向ACS添加服务标识并设置对称密钥时,似乎ACS正在更改我发送的密钥。

如果我传入“xyz123”作为对称密钥的值...当我进入ACS管理门户并查看该值时,它是一个不同的字符串;我们可以说“AHDyDG6236 =”。

如果我向API询问它返回给我的值“xyz123”(ServiceIdentityKey.Value)。

您需要登录的值是“AHDyDG6236 =”但是如果没有进入ACS门户并点击“显示键”按钮,就无法获得此值?

无论如何都可以获得对称密钥的可用值而无需进入ACS管理门户网站?

这里有一些示例代码,说明了我在说什么。它基于以下示例:http://msdn.microsoft.com/en-us/library/hh135148.aspx

    var svc = ManagementServiceHelper.CreateManagementServiceClient();
    var password = Encoding.UTF8.GetBytes("password");
    var serviceIdentity = svc.CreateServiceIdentity("testSI", password, ServiceIdentityKeyType.Symmetric, ServiceIdentityKeyUsage.Password);
    serviceIdentity.Description = "service identity for testing";
    svc.SaveChangesBatch();
    var svc2 = ManagementServiceHelper.CreateManagementServiceClient();
    var si = svc2.GetServiceIdentityByName("testSI");
    Console.WriteLine(Encoding.UTF8.GetChars(si.ServiceIdentityKeys[0].Value)); //prints out "password"

运行此代码后,转到ACS门户并单击对称密钥,然后单击“显示密钥”,它会显示生成/散列值...这是您需要进行身份验证的值...但是没有办法从API获得这个价值?

2 个答案:

答案 0 :(得分:2)

您遇到的问题是 Encoding.UTF8.GetBytes("密码")。

发送到服务器的字符串被编码到base64中,因此您需要使用不同的函数来获取字节数组。 的 Convert.FromBase64String("密码&#34)

此页面上的示例是错误的,但我已联系他们的团队让他们知道,并希望他们会解决它。 How to use Access Control Service

答案 1 :(得分:0)

我希望它会忽略您发送的密钥 - 您创建服务标识,ACS将生成一个新密钥,并使其可用于将来的会话。请参阅此页面上的“证书和密钥管理指南”:http://www.windowsazure.com/en-us/manage/services/other/manage-acs/以了解ACS如何允许您管理密钥。