我正在尝试通过发送“usernametoken”soap 请求来使用 ONVIF 摄像头进行身份验证以获取设备功能。但是我从相机中收到“请求的操作需要授权,并且发件人未经授权”错误。以下是我发送的“用户名令牌”:
<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>root</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">PLAolzuaeKGkHrC7uMD52ZAvjDc=</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">DK81s1X+o0Cp0QfDg7CJ8YSeacg=</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-02-12T21:49:39.001Z</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCapabilities xmlns="http://www.onvif.org/ver10/device/wsdl"><Category>All</Category></GetCapabilities></s:Body></s:Envelope>
我创建“nonce”是这样的:
string guid = Guid.NewGuid().ToString();
string nonce = GetSHA1String( guid );
public string GetSHA1String(string phrase)
{
byte[] hashedDataBytes = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(phrase));
return Convert.ToBase64String(hashedDataBytes);
}
我正在以这种方式创建“创建”:
string created = System.DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
我正在以这种方式创建 PasswordDigest:
string pwd = "admin";
string hashedPassword = CreateHashedPassword(nonce, created, pwd);
public string CreateHashedPassword(string nonce, string created, string password)
{
return GetSHA1String(nonce + created + password);
}
我不知道我做错了什么。我真的很感激有人可以在这件事上提供帮助。