:param hmac_secret: optional HMAC
    :type hmac_secret: :class:`bytes`
    :return: (session_key, encrypted_session_key) tuple
    :rtype: :class:`tuple`
481625
def generate_session_key(hmac_secret=b''):
    
    session_key = random_bytes(32)
    encrypted_session_key = PKCS1_OAEP.new(UniverseKey.Public, SHA1)\
                                      .encrypt(session_key + hmac_secret)

    return (session_key, encrypted_session_key)
939833
def get_common_session_key_proof_hash(self, session_key, session_key_proof, client_public):
        
        return self.hash(client_public, session_key_proof, session_key, as_bytes=True)
410208
def core_hmac_sha1(key, data)
      bkey = str2binb(key)
      bkey = core_sha1(bkey, key.length * $chrsz) if bkey.length > 16

      ipad = Array.new(16, 0)
      opad = Array.new(16, 0)
      # for(var i = 0; i < 16; i++)
      i = 0
      while i < 16
        ipad[i] = (bkey[i] || 0) ^ 0x36363636
        opad[i] = (bkey[i] || 0) ^ 0x5C5C5C5C
        i += 1
      end

      hash = core_sha1((ipad + str2binb(data)), 512 + data.length * $chrsz)
      core_sha1((opad + hash), 512 + 160)
    end
401925
def DecryptPassword(cipher, key):
		
		import base64
		import hmac
		import sha
		from array import array

		H = UcsUtils.GetShaHash

		cipher = cipher + "\n"
		cipher = base64.decodestring(cipher)
		n = len(cipher) - 16 - 8

		uhash = cipher[:16]
		passwordStream = cipher[16:-8] + "0000"[n & 3:]
		auth = cipher[-8:]

		k_enc, k_auth = H('enc' + key + uhash), H('auth' + key + uhash)
		vauth = hmac.new(cipher[-8:], k_auth, sha).digest()[:8]

		passwordStream = array('L', passwordStream)
		xkey = UcsUtils.Expandkey(k_enc, n + 4)

		for i in xrange(len(passwordStream)):
			passwordStream[i] = passwordStream[i] ^ xkey[i]

		decryptedPassword = passwordStream.tostring()[:n]
		return decryptedPassword
216170
def get_jwt_secret():
    
    secret_key = __options__.get("jwt_secret") or config("JWT_SECRET") or config("SECRET_KEY")
    if not secret_key:
        raise exceptions.AuthError("Missing config JWT/SECRET_KEY")
    return secret_key
1227084
def _convert_key_to_str(key):
    '''
    
    '''
    # IMPORTANT: on PY2, the secret key must be str and not unicode to work
    # properly with hmac.new (see http://bugs.python.org/issue5285)
    #
    # pylint: disable=incompatible-py3-code,undefined-variable
    return salt.utils.data.encode(key) \
        if six.PY2 and isinstance(key, unicode) \
        else key
178101
def get_cookie(self, key, secret=None):
        
        value = self.COOKIES.get(key)
        if secret and value:
            dec = cookie_decode(value, secret) # (key, value) tuple or None
            return dec[1] if dec and dec[0] == key else None
        return value or None
1256435
public static byte[] HmacSha1(byte[] binaryData, String key) throws Exception {
		try {
			Mac mac = Mac.getInstance(HMAC_SHA1);
			SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1);
			mac.init(secretKey);
			byte[] HmacSha1Digest = mac.doFinal(binaryData);
			return HmacSha1Digest;
			
		} catch (NoSuchAlgorithmException e) {
			LOG.error("mac not find algorithm {}", HMAC_SHA1);
			throw e;
		} catch (InvalidKeyException e) {
			LOG.error("mac init key {} occur a error {}", key, e.toString());
			throw e;
		} catch (IllegalStateException e) {
			LOG.error("mac.doFinal occur a error {}", e.toString());
			throw e;
		}
	}
1074013
def get_hmac(self, key):
        
        h = HMAC.new(key, None, SHA256)
        h.update(str(self.index).encode())
        h.update(self.seed)
        h.update(str(self.n).encode())
        h.update(self.root)
        h.update(str(self.timestamp).encode())
        return h.digest()
809522
def _sign(self, data):
        

        # Python2/3 urlencode aren't good enough for this task.
        params = "&".join(
            "=".join((key, cs_encode(value)))
            for key, value in sorted(data.items())
        )

        digest = hmac.new(
            self.secret.encode('utf-8'),
            msg=params.lower().encode('utf-8'),
            digestmod=hashlib.sha1).digest()

        return base64.b64encode(digest).decode('utf-8').strip()
918549
def encrypt_key(password, salt)
      iterations, length = CRYPTERATIONS, HASH_BYTE_SIZE
      OpenSSL::PKCS5::pbkdf2_hmac_sha1(password, salt, iterations, length)
    end
473449
function hmacSha256(key, data) {
    if (subtle) {
        var algo = { name: 'HMAC', hash: { name: 'SHA-256' } };
        return subtle.importKey('raw', key, algo, false, ['sign'])
            .then(function(subtleKey) {
                return subtle.sign(algo, subtleKey, data);
            });
    } else if (nodeCrypto) {
        return new Promise(function(resolve) {
            var hmac = nodeCrypto.createHmac('sha256', Buffer.from(key));
            var hash = hmac.update(Buffer.from(data)).digest();
            resolve(hash.buffer);
        });
    } else {
        return Promise.reject(new KdbxError(Consts.ErrorCodes.NotImplemented, 'HMAC-SHA256 not implemented'));
    }
}
1170863
def _hmac_auth(self):
        """"""
        return TcExHmacAuth(self.args.api_access_id, self.args.api_secret_key, self.tcex.log)
116638
def _compute_signature(parameters, access_key_secret, method, path):
    '''
    
    '''
    parameters['signature_method'] = 'HmacSHA256'

    string_to_sign = '{0}\n{1}\n'.format(method.upper(), path)

    keys = sorted(parameters.keys())
    pairs = []
    for key in keys:
        val = six.text_type(parameters[key]).encode('utf-8')
        pairs.append(_quote(key, safe='') + '=' + _quote(val, safe='-_~'))
    qs = '&'.join(pairs)
    string_to_sign += qs

    h = hmac.new(access_key_secret, digestmod=sha256)
    h.update(string_to_sign)

    signature = base64.b64encode(h.digest()).strip()

    return signature
742179
def expected_signature(self):
        
        k_secret = b"AWS4" + self.key_mapping[self.access_key].encode("utf-8")
        k_date = hmac.new(k_secret, self.request_date.encode("utf-8"),
                          sha256).digest()
        k_region = hmac.new(k_date, self.region.encode("utf-8"),
                            sha256).digest()
        k_service = hmac.new(k_region, self.service.encode("utf-8"),
                             sha256).digest()
        k_signing = hmac.new(k_service, _aws4_request_bytes, sha256).digest()

        return hmac.new(k_signing, self.string_to_sign.encode("utf-8"),
                        sha256).hexdigest()
733686
def generate_hotp(secret, counter=4):
    
    # https://tools.ietf.org/html/rfc4226
    msg = struct.pack('>Q', counter)
    digest = hmac.new(to_bytes(secret), msg, hashlib.sha1).digest()

    ob = digest[19]
    if PY2:
        ob = ord(ob)

    pos = ob & 15
    base = struct.unpack('>I', digest[pos:pos + 4])[0] & 0x7fffffff
    token = base % 1000000
    return token
1122020
function() {
      var cert = this.keychain.getCertPem();
      if (!cert) {
        throw new CError('missing certificate').log();
      }
      var tmp = this.getDate() + '::' + cert + '::' + SECRET_CLIENT;
      var hmac = forge.hmac.create();
      hmac.start('sha256', SECRET);
      hmac.update(tmp);
      return hmac.digest().toHex();
    }