Generates a string to be signed for the specified signature version.

(currently only generates strings for V2 signing)

@param {*} canonicalRequest
553733
function getStringToSign(canonicalRequest) {
  return [
    canonicalRequest.method,
    canonicalRequest.contentMD5,
    canonicalRequest.contentType,
    canonicalRequest.timestamp,
    ...canonicalRequest.amzHeaders,
    canonicalRequest.querystring
      ? `${canonicalRequest.uri}?${canonicalRequest.querystring}`
      : canonicalRequest.uri
  ].join("\n");
}
949368
private function generateSignature(DOMElement $signedInfoNode)
    {
        $signature = null;

        if (!openssl_sign(
            $signedInfoNode->C14N(true),
            $signature,
            $this->getPrivateKeyResource(),
            OPENSSL_ALGO_SHA1
        )
        ) {
            throw new \Exception('Unable to sign the request');
        }

        return $signature;
    }
834506
function signature(opt) {

  var options = opt || Object.create(null);
  var my = {
    header: String(options.header || 'Server'),
    signature: String(options.signature || 'Nodejs'),
    token: String(options.token || 'Full'),
    custom: options.custom,
    extra: options.extra,
    standalone: Boolean(options.standalone)
  };
  if (my.token == 'Full') {
    my.Prod = my.Major = my.Minor = my.Min = my.OS = true;
  } else if (my.token == 'OS') {
    my.Prod = my.Major = my.Minor = my.Min = my.OS = true;
  } else if (my.token == 'Min') {
    my.Prod = my.Major = my.Minor = my.Min = true;
  } else if (my.token == 'Minor') {
    my.Prod = my.Major = my.Minor = true;
  } else if (my.token == 'Major') {
    my.Prod = my.Major = true;
  } else if (my.token == 'Prod') {
    my.Prod = true;
  }
  return wrapper(my);
}
194932
function( signature, input, key ) {

    var check = this.sign( input, key )

    return signature.toString( 'hex' ) ===
      check.toString( 'hex' )

  }
492229
private final byte[] deriveSigningKey(AWSCredentials credentials,
            AWS4SignerRequestParams signerRequestParams) {

        final String cacheKey = computeSigningCacheKeyName(credentials,
                signerRequestParams);
        final long daysSinceEpochSigningDate = DateUtils
                .numberOfDaysSinceEpoch(signerRequestParams
                        .getSigningDateTimeMilli());

        SignerKey signerKey = signerCache.get(cacheKey);

        if (signerKey != null) {
            if (daysSinceEpochSigningDate == signerKey
                    .getNumberOfDaysSinceEpoch()) {
                return signerKey.getSigningKey();
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Generating a new signing key as the signing key not available in the cache for the date "
                    + TimeUnit.DAYS.toMillis(daysSinceEpochSigningDate));
        }
        byte[] signingKey = newSigningKey(credentials,
                signerRequestParams.getFormattedSigningDate(),
                signerRequestParams.getRegionName(),
                signerRequestParams.getServiceName());
        signerCache.add(cacheKey, new SignerKey(
                daysSinceEpochSigningDate, signingKey));
        return signingKey;
    }
237024
function(expectedSignature) {
        var signature = this.reader.readString(4);
        if (signature !== expectedSignature) {
            throw new Error("Corrupted zip or bug : unexpected signature " + "(" + utils.pretty(signature) + ", expected " + utils.pretty(expectedSignature) + ")");
        }
    }
350290
def string_to_sign(more_attributes)
      attributes_for_signing = self.attributes_for_signing.merge(more_attributes)
      missing_attributes = self.class::SIGNATURE_COMPONENTS.select { |key| !attributes_for_signing.key?(key) || attributes_for_signing[key].nil? }
      missing_attributes.delete(:body) # body may be omitted
      if missing_attributes.any?
        raise(UnableToSignError, "Missing required attributes to sign: #{missing_attributes.inspect}\non object to sign: #{inspect}")
      end
      string = self.class::SIGNATURE_COMPONENTS.map { |k| attributes_for_signing[k].to_s }.join("\n")
      Digest::SHA512.hexdigest(string)
    end
1036511
public static String generate(String encrypt, String signature, String timestamp, String nonce) {

		String format = "<xml>\n" + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n"
				+ "<MsgSignature><![CDATA[%2$s]]></MsgSignature>\n"
				+ "<TimeStamp>%3$s</TimeStamp>\n" + "<Nonce><![CDATA[%4$s]]></Nonce>\n" + "</xml>";
		return String.format(format, encrypt, signature, timestamp, nonce);

	}
730704
function signAWSRequest({ credentials, request }) {
  const signer = new AWS.Signers.V4(request, 'es')
  signer.addAuthorization(credentials, new Date())
  return request
}
905650
function Sign(key) {
    var self = this;

    /** default encoding to use in all string operations */
    self.defaultEncoding = undefined;

    if( key instanceof SignKey) {
        self.iKey = key;
    }
    else {
        /** Set of keys used to encrypt and decrypt messages */
        self.iKey = new SignKey();
    }

    /** Size of the generated message signature */
    self.bytes = function() {
        return binding.crypto_sign_BYTES;
    };

    /** String name of the default crypto primitive used in sign operations */
    self.primitive = function() {
        return binding.crypto_sign_PRIMITIVE;
    };

    /**
     * Get the keypair object
     * @returns {SignKey|*}
     */
    self.key = function() {
        return self.iKey;
    };

    /**
     * @return {Number} The size of the message signature
     */
    self.size = function() {
        return binding.crypto_sign_BYTES;
    };

    /**
     * Set the default encoding to use in all string conversions
     * @param {String} encoding  encoding to use
     */
    self.setEncoding = function(encoding) {
        assert(!!encoding.match(/^(?:utf8|ascii|binary|hex|utf16le|ucs2|base64)$/), 'Encoding ' + encoding + ' is currently unsupported.');
        self.defaultEncoding = encoding;
    };

    /**
     * Get the current default encoding
     * @returns {undefined|String}
     */
    self.getEncoding = function() {
        return self.defaultEncoding;
    };

    /**
     * Digitally sign message
     *
     * @param {Buffer|String|Array} message  message to sign
     * @param {String} [encoding]             encoding of message string
     *
     * @returns {Object}                       cipher box
     */
    self.sign = function (message, encoding) {
        encoding = String(encoding) || self.defaultEncoding || 'utf8';

        var buf = toBuffer(message, encoding);

        var signature = binding.crypto_sign(buf, self.iKey.sk().get());
        if( !signature ) {
            return undefined;
        }

        return {
            sign: signature,
            publicKey: self.iKey.pk().get()
        };
    };

    /**
     * Digitally sign message, using detached signature
     *
     * @param {Buffer|String|Array} message  message to sign
     * @param {String} [encoding]            encoding of message string
     *
     * @returns {Object} cipher box
     */
    self.signDetached = function (message, encoding) {
        encoding = String(encoding) || self.defaultEncoding || 'utf8';

        var buf = toBuffer(message, encoding);

        var signature = binding.crypto_sign_detached(buf, self.iKey.sk().get());
        if( !signature ) {
            return undefined;
        }

        return {
            sign: signature,
            publicKey: self.iKey.pk().get()
        };
    };
}
352266
function signatureBaseString(requestMethod, uri, body, protocolParams) {
    return [
        encode(requestMethod.toUpperCase()),
        encode(baseStringUri(uri)),
        encode(normalizedRequestParameters(uri, body, protocolParams))
    ].join('&');
}
209276
def gen_str_to_sign(self, req):
        """"""
        url = urlsplit(req.url)
        bucket_name = url.netloc.split(".", 1)[0]

        logger.debug(req.headers.items())
        ucloud_headers = [
            (k, v.strip())
            for k, v in sorted(req.headers.lower_items())
            if k.startswith("x-ucloud-")
        ]
        canonicalized_headers = "\n".join([
            "{0}:{1}".format(k, v) for k, v in ucloud_headers
        ])

        canonicalized_resource = "/{0}{1}".format(
            bucket_name,
            unquote(url.path)
        )

        str_to_sign = "\n".join([
            req.method,
            req.headers.get("content-md5", ""),
            req.headers.get("content-type", ""),
            req.headers.get("date", self._expires),
            canonicalized_headers + canonicalized_resource
        ])
        return str_to_sign
501370
function(signer) {
      if('content' in msg) {
        throw new Error('PKCS#7 signing not yet implemented.');
      }

      if(typeof msg.content !== 'object') {
        // use Data ContentInfo
        msg.contentInfo = asn1.create(
          asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
            // ContentType
            asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
              asn1.oidToDer(forge.pki.oids.data).getBytes())
          ]);

        // add actual content, if present
        if('content' in msg) {
          msg.contentInfo.value.push(
            // [0] EXPLICIT content
            asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
              asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
                msg.content)
            ]));
        }
      }

      // TODO: generate digest algorithm identifiers

      // TODO: generate signerInfos
    }
1213293
public static String toCanonicalForm(CharSequence input) {
      if (input == null) {
         return null;
      }
      return StringFunctions.CANONICAL_NORMALIZATION.apply(input.toString());
   }
603596
def parse_signed_by(content, canonicalize=True):
    
    s = content[-300:]
    m = _SIGNER_PATTERN.search(s) or _SIGNER_PATTERN2.search(s)
    if not m:
        return []
    signers = m.group(1)
    tmp_signers = signers.upper()
    if tmp_signers in (u'CONFIDENTIAL', u'UNCLASSIFIED'):
        return []
    if canonicalize:
        tmp_signers = tuple(re.split(ur'\s+', tmp_signers.strip()))
        if tmp_signers == (u'KEEGANPAAL',): # 04TAIPEI3991
            signers = [u'KEEGAN', u'PAAL']
        elif tmp_signers == (u'JOHNSONKEANE',): # 05ASUNCION807
            signers = [u'JOHNSON', u'KEANE']
        elif tmp_signers == (u'STEWARTBALTIMORE',): # 06MUSCAT396
            signers = [u'STEWART', u'BALTIMORE']
        elif tmp_signers == (u'BIGUSBELL',): # 06KIRKUK112
            signers = [u'BIGUS', u'BELL']
        else:
            signers = tmp_signers
    else:
        signers = [signers]
    return [c14n.canonicalize_surname(s) for s in signers] if canonicalize else signers
401162
private String createSignature(Credentials credentials, String secretKey) {
        return new SignatureGenerator().generate(
                secretKey,
                credentials.getMethod(),
                credentials.getTimestamp(),
                credentials.getPath(),
                credentials.getContent());
    }
724679
def generate_signature(params, returns, condition=nil)
      params = params.split(//) if params.respond_to?(:split) # Convert params string into array
      params.map! {|param| TYPES[param.to_sym] || param} # Convert chars into FFI type symbols
      returns = TYPES[returns.to_sym] || returns # Convert chars into FFI type symbols
      [params, returns, condition]
    end