我在使用 ACS 管理 API 和对称 key 时遇到一些问题。当我通过 API 将服务身份添加到 ACS 并设置对称 key 时,似乎 ACS 正在更改我发送的 key 。
如果我传入“xyz123”作为对称 key 的值...当我转到 ACS 管理门户并查看该值时,它是一个不同的字符串;可以说“AHDyDG6236=”。
如果我向 API 询问值,它会返回给我“xyz123”(ServiceIdentityKey.Value)。
您需要登录的值为“AHDyDG6236=”,但如果不转到 ACS 门户并单击“显示 key ”按钮,就无法获取该值吗?
有没有办法无需进入 ACS 管理门户即可获取对称 key 的可用值?
这里有一些示例代码来说明我正在谈论的内容。它基于此处找到的示例: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 门户并单击对称 key ,然后单击“显示 key ”,它会显示生成的/散列值...这是您进行身份验证所需的值...但是有没有办法从 API 获取该值?
最佳答案
您遇到的问题是在 Encoding.UTF8.GetBytes("password") 中。
发送到服务器的字符串被编码为 base64,因此您需要使用不同的函数来获取字节数组。 Convert.FromBase64String("密码")
此页面上的示例是错误的,但我已联系他们的团队让他们知道,并希望他们能够修复它。 How to use Access Control Service
关于azure - 如何从 Azure ACS 获取对称 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19963680/