****************************************
【hmac】加密
****************************************
349474
function hmac(str, secret = '', encoding = 'hex') {
    return crypto.createHmac('sha256', secret).update(str, 'utf8').digest(encoding);
}
924091
public static String hmacSHA256(String data, String key) {
        return hmacSHA256(data.getBytes(), key.getBytes());
    }
737489
function core_hmac_sha256(key, data)
{
    var bkey = str2binb(key);
    if(bkey.length > 16) bkey = core_sha256(bkey, key.length * chrsz);

    var ipad = Array(16), opad = Array(16);
    for(var i = 0; i < 16; i++) {
        ipad[i] = bkey[i] ^ 0x36363636;
        opad[i] = bkey[i] ^ 0x5C5C5C5C;
    }
    var hash = core_sha256(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
    return core_sha256(opad.concat(hash), 512 + 256);
}
534511
public static String encryptPin(String accNo, String pin, String encoding,
			PublicKey key) {
		/** 使用公钥对密码加密 **/
		byte[] data = null;
		try {
			data = pin2PinBlockWithCardNO(pin, accNo);
			data = encryptData(key, data);
			return new String(SecureUtil.base64Encode(data), encoding);
		} catch (Exception e) {
			LogUtil.writeErrorLog(e.getMessage(), e);
			return "";
		}
	}
915610
private function createHmac(
        string $iv,
        string $keySalt,
        string $cipher,
        string $value,
        string $authenticationKey
    ) : string {
        return \hash_hmac(self::$hmacAlgorithm, self::$version . $cipher . $iv . $keySalt . $value, $authenticationKey);
    }
393182
function (input, signature, b64safeKey, alg) {
  var key = new Buffer( b64url.b64( b64safeKey ), 'base64' )
  var hmac = crypto.createHmac( alg, key ).update( input )
  var inputSignature = b64url.safe( hmac.digest( 'base64' ) )
  return (inputSignature === signature)
}
270778
private static void doCheck(String appId, String cpId, String privateKey, String publicKey, GameUserData userData, ICheckLoginSignHandler callback) {
        // 创建body参数
        byte[] body = getRequestBody(appId, cpId, privateKey, userData);

        // 发送请求
        sendRequest(URL, body, publicKey, callback);
    }
1352230
def sign_hmac(secret, payload):
    
    payload = payload.encode('ascii', 'strict')
    secret = secret.encode('ascii', 'strict')
    sig = hmac.new(base64.urlsafe_b64decode(secret), payload, hashlib.sha1)
    out = base64.urlsafe_b64encode(sig.digest())
    return out.decode('utf-8')
596210
public byte[] hmac(byte[] key)
	{
		try {
			Key secretKey = new SecretKeySpec(key, "HmacSHA1");
			Mac hmac_algo = Mac.getInstance("HmacSHA1");
			hmac_algo.init(secretKey);
			hmac_algo.update(this.data);
			for(Entry<String, byte[]> a: this.annotations.entrySet())   // this is in a fixed order because it is a SortedMap
			{
				if(!a.getKey().equals("HMAC"))
					hmac_algo.update(a.getValue());
			}
			return hmac_algo.doFinal();
		} catch (NoSuchAlgorithmException e) {
			throw new PyroException("invalid hmac algorithm",e);
		} catch (InvalidKeyException e) {
			throw new PyroException("invalid hmac key",e);
		}
	}
975959
def HMAC(self, message, use_sha256=False):
    """"""
    h = self._NewHMAC(use_sha256=use_sha256)
    h.update(message)
    return h.finalize()
1243555
function(key, seqNum, record) {
  /* MAC is computed like so:
  HMAC_hash(
    key, seqNum +
      TLSCompressed.type +
      TLSCompressed.version +
      TLSCompressed.length +
      TLSCompressed.fragment)
  */
  var hmac = forge.hmac.create();
  hmac.start('SHA1', key);
  var b = forge.util.createBuffer();
  b.putInt32(seqNum[0]);
  b.putInt32(seqNum[1]);
  b.putByte(record.type);
  b.putByte(record.version.major);
  b.putByte(record.version.minor);
  b.putInt16(record.length);
  b.putBytes(record.fragment.bytes());
  hmac.update(b.getBytes());
  return hmac.digest().getBytes();
}
533876
def _add_header_client_encryption_hmac(request_bytes, key, iv, custom_headers):
    

    hashed = hmac.new(key, iv + request_bytes, sha1)
    hashed_base64 = base64.b64encode(hashed.digest()).decode()
    custom_headers[_HEADER_CLIENT_ENCRYPTION_HMAC] = hashed_base64
1145071
public PrivateKey unwrapPrivateKeyByKey(byte[] key,Key unwrapKey)
	{
		try {
    		if(key==null || key.length<=0 || unwrapKey==null)
    		{
    			return null;
    		}
			Cipher cipher=Cipher.getInstance(algorithm);
			//使用私钥包裹模式
			cipher.init(Cipher.UNWRAP_MODE,unwrapKey);
			return (PrivateKey) cipher.unwrap(key, algorithm,Cipher.PRIVATE_KEY);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
    	return null;
	}
1040655
final byte[] hmac(final byte[] input, final int offset, final int len) {
		hMac.update(input, offset, len);
		return hMac.doFinal();
	}
677652
def sign_hmac(secret, payload)
      secret = secret.encode('ASCII')
      payload = payload.encode('ASCII')

      # Decode the private key
      raw_key = Base64.urlsafe_decode64(secret)

      # Create a signature using the private key and the URL
      digest = OpenSSL::Digest.new('sha1')
      raw_signature = OpenSSL::HMAC.digest(digest, raw_key, payload)

      # Encode the signature into base64 for url use form.
      signature =  Base64.urlsafe_encode64(raw_signature)
      return signature
    end
1009714
def verify_hmac(self, data):
        
        hmac = HMAC(self.SK_ar, digestmod=sha256)
        hmac_theirs = data[-MACLEN:]
        hmac.update(data[:-MACLEN])
        hmac_ours = hmac.digest()[:MACLEN]
        logger.debug('HMAC verify (ours){} (theirs){}'.format(
            binascii.hexlify(hmac_ours), binascii.hexlify(hmac_theirs)))
        if hmac_ours != hmac_theirs:
            raise IkeError('HMAC verify failed')
469061
def b64_hmac_md5(key, data):
    
    bdigest = base64.b64encode(hmac.new(key, data, _md5).digest()).strip().decode("utf-8")
    return re.sub('=+$', '', bdigest)