Calculates the HMAC for a given message.
975959
def HMAC(self, message, use_sha256=False):
    """"""
    h = self._NewHMAC(use_sha256=use_sha256)
    h.update(message)
    return h.finalize()
121472
private byte[] hmac(byte[] key, byte[] data) {
        try {
            final Mac mac = Mac.getInstance(hmacAlgorithm);
            mac.init(new SecretKeySpec(key, mac.getAlgorithm()));
            return mac.doFinal(data);
        } catch (InvalidKeyException e) {
            if (key.length == 0) {
                throw new UnsupportedOperationException("This JVM does not support empty HMAC keys (empty passwords). "
                        + "Please set a bucket password or upgrade your JVM.");
            } else {
                throw new RuntimeException("Failed to generate HMAC hash for password", e);
            }
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }
866351
def wrap(self, message):
        
        cipher_text = _Ntlm2Session.encrypt(self, message)
        signature = _Ntlm2Session.sign(self, message)
        return cipher_text, signature
706835
def derive_signature(key, qs):
    """"""
    key, qs = (key or "", qs or "")
    return hmac.new(key.encode(), qs.encode(), hashlib.sha1).hexdigest()
293388
public void
applyStream(Message m, TSIGRecord old, boolean first) {
	if (first) {
		apply(m, old);
		return;
	}
	Date timeSigned = new Date();
	int fudge;
	hmac.reset();

	fudge = Options.intValue("tsigfudge");
	if (fudge < 0 || fudge > 0x7FFF)
		fudge = FUDGE;

	DNSOutput out = new DNSOutput();
	out.writeU16(old.getSignature().length);
	hmac.update(out.toByteArray());
	hmac.update(old.getSignature());

	/* Digest the message */
	hmac.update(m.toWire());

	out = new DNSOutput();
	long time = timeSigned.getTime() / 1000;
	int timeHigh = (int) (time >> 32);
	long timeLow = (time & 0xFFFFFFFFL);
	out.writeU16(timeHigh);
	out.writeU32(timeLow);
	out.writeU16(fudge);

	hmac.update(out.toByteArray());

	byte [] signature = hmac.doFinal();
	byte [] other = null;

	Record r = new TSIGRecord(name, DClass.ANY, 0, alg, timeSigned, fudge,
				  signature, m.getHeader().getID(),
				  Rcode.NOERROR, other);
	m.addRecord(r, Section.ADDITIONAL);
	m.tsigState = Message.TSIG_SIGNED;
}
1039541
def _hash(self, iv, value):
        
        return hmac.new(self.key, msg=iv+value, digestmod=hashlib.sha256).hexdigest()
83101
function hmac(text, format) {
    format = format || 'hex';
    return crypto.createHmac('sha256', cryptoKey).update(text).digest(format);
  }
739590
@Override
    public String sign(String message, byte[] key) {
        Preconditions.checkNotNull(message);
        Preconditions.checkNotNull(key);
        try {
            // Get an hmac_sha1 key from the raw key bytes
            SecretKeySpec signingKey = new SecretKeySpec(key, HMAC_SHA_1);

            // Get an hmac_sha1 Mac instance and initialize with the signing key
            Mac mac = Mac.getInstance(HMAC_SHA_1);
            mac.init(signingKey);

            // Compute the hmac on input data bytes
            byte[] rawHmac = mac.doFinal(message.getBytes(Charsets.UTF_8));

            // Convert raw bytes to Hex
            return hexToString(rawHmac);
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }
1226650
def compute(self):
        """"""
        if "Signature" in self.params:
            raise RuntimeError("Existing signature in parameters")
        if self.signature_version is not None:
            version = self.signature_version
        else:
            version = self.params["SignatureVersion"]
        if str(version) == "1":
            bytes = self.old_signing_text()
            hash_type = "sha1"
        elif str(version) == "2":
            bytes = self.signing_text()
            if self.signature_method is not None:
                signature_method = self.signature_method
            else:
                signature_method = self.params["SignatureMethod"]
            hash_type = signature_method[len("Hmac"):].lower()
        else:
            raise RuntimeError("Unsupported SignatureVersion: '%s'" % version)
        return self.creds.sign(bytes, hash_type)
126666
private byte[] calculateHash(String data) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
        md.update(data.getBytes(ENCODING));
        return md.digest();
    }
876777
function rstr_hmac(key, data) {
        key = (utf8) ? utf8Encode(key) : key;
        data = (utf8) ? utf8Encode(data) : data;
        var hash, i = 0,
          bkey = rstr2binb(key),
          ipad = Array(16),
          opad = Array(16);

        if (bkey.length > 16) {
          bkey = binb(bkey, key.length * 8);
        }

        for (; i < 16; i += 1) {
          ipad[i] = bkey[i] ^ 0x36363636;
          opad[i] = bkey[i] ^ 0x5C5C5C5C;
        }

        hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
        return binb2rstr(binb(opad.concat(hash), 512 + 256));
      }
984488
def message_checksum(msg):
    ''''''
    from .mavcrc import x25crc
    crc = x25crc()
    crc.accumulate_str(msg.name + ' ')
    # in order to allow for extensions the crc does not include
    # any field extensions
    crc_end = msg.base_fields()
    for i in range(crc_end):
        f = msg.ordered_fields[i]
        crc.accumulate_str(f.type + ' ')
        crc.accumulate_str(f.name + ' ')
        if f.array_length:
            crc.accumulate([f.array_length])
    return (crc.crc&0xFF) ^ (crc.crc>>8)
1216087
function hmac(key, string, encoding) {
  return crypto.createHmac('sha256', key).update(string, 'utf8').digest(encoding)
}
98132
def calculate_signature(key, data, timestamp=None):
    
    # Create a timestamp if one was not given
    if timestamp is None:
        timestamp = int(time.time())

    # Construct the message from the timestamp and the data in the request
    message = str(timestamp) + ''.join("%s%s" % (k,v) for k,v in sorted(data.items()))

    # Calculate the signature (HMAC SHA256) according to RFC 2104
    signature = hmac.HMAC(str(key), message, hashlib.sha256).hexdigest()

    return signature
499162
def _generate_appsecret_proof(self):
        
        if six.PY2:
            key = self.appsecret
            message = self.oauth_token
        else:
            key = bytes(self.appsecret, 'utf-8')
            message = bytes(self.oauth_token, 'utf-8')

        return hmac.new(key, message, hashlib.sha256).hexdigest()
1183318
def hmac(key, message, tag=None, alg=hashlib.sha256):
    
    return HMAC.new(str(key), str(tag) + str(message), digestmod=alg).digest()
1096249
def compute_header_hmac_hash(context):
    """"""

    return hmac.new(
        hashlib.sha512(
            b'\xff' * 8 +
            hashlib.sha512(
                context._.header.value.dynamic_header.master_seed.data +
                context.transformed_key +
                b'\x01'
            ).digest()
        ).digest(),
        context._.header.data,
        hashlib.sha256
    ).digest()