createHeaders static method

Map<String, dynamic> createHeaders(
  1. String url
)

根据路径生成认证header

海康isc平台采用AK/SK认证,需要生成生成必要的秘钥放到header中

'url' 接口请求地址 比如previewURLs,controlling..等

Implementation

static Map<String, dynamic> createHeaders(String url) {
  assert(ArtemisConfig.host != null);
  assert(ArtemisConfig.appKey != null);
  assert(ArtemisConfig.appSecret != null);

  var httpHeaders = "POST\n*/*\napplication/json\n";
  var customHeaders = "x-ca-key:${ArtemisConfig.appKey}\n";
  var msg = httpHeaders + customHeaders + url;
  var secretBytes = utf8.encode(ArtemisConfig.appSecret!);
  var messageBytes = utf8.encode(msg);
  var digest = Hmac(sha256, secretBytes).convert(messageBytes);
  var signature = base64Encode(digest.bytes);

  Map<String, dynamic> headers = Map();
  headers["Accept"] = "*/*";
  headers["Content-Type"] = "application/json";
  headers["X-Ca-Key"] = ArtemisConfig.appKey;
  headers["X-Ca-Signature"] = signature;
  headers["X-Ca-Signature-Headers"] = "x-ca-key";
  return headers;
}