getSignature method

String getSignature()

Implementation

String getSignature() {
  final keyTime = generateKeyTime(startTimeMs, expiredTimeMs);
  final signKey = generateSignKey(keyTime, secretKey);
  final (paramList: urlParamList, parameters: httpParameters) =
      generateParamsListAndParameters(params ?? {});
  final (paramList: headerList, parameters: httpHeaders) =
      generateParamsListAndParameters(filterHeaders(headers ?? {}));
  final httpString = generateHttpString(
      method: method,
      uriPathname:
          uriPathname.startsWith('/') ? uriPathname : '/$uriPathname',
      httpParameters: httpParameters,
      httpHeaders: httpHeaders);
  final stringToSign = generateStringToSign(keyTime, httpString);
  final signature = generateSignature(stringToSign, signKey);

  final result = [
    'q-sign-algorithm=sha1',
    'q-ak=$secretId',
    'q-sign-time=$keyTime',
    'q-key-time=$keyTime',
    'q-header-list=$headerList',
    'q-url-param-list=$urlParamList',
    'q-signature=$signature'
  ].join('&');

  COSLogger.t(
      '\nSignKey: $signKey \nHttpString: $httpString \nStringToSign: $stringToSign \nResult: $result');

  return result;
}