创建HMac对象，调用digest方法可获得hmac值

@param algorithm {@link HmacAlgorithm}
@param key 密钥，如果为<code>null</code>生成随机密钥
@return {@link HMac}
@since 3.3.0
170131
public static HMac hmac(HmacAlgorithm algorithm, String key) {
		return new HMac(algorithm, StrUtil.utf8Bytes(key));
	}
720299
def algorithm=(alg)
      @algorithm = begin
        case alg.to_s
        when 'hmac-sha-1'
          OpenSSL::Digest::SHA1.new
        when 'hmac-sha-256'
          OpenSSL::Digest::SHA256.new
        else
          raise(ArgumentError, 'Unsupported algorithm')
        end
      end
    end
656065
public static byte[] sha1hmac(byte[] key, byte[] text) throws IllegalArgumentException
	{
		try
		{
			SecretKey sk = new SecretKeySpec(key, "HMACSHA1");
			Mac m = Mac.getInstance(sk.getAlgorithm());
			m.init(sk);
			return m.doFinal(text);
		}
		catch (InvalidKeyException e)
		{
			throw new IllegalArgumentException(e);
		}
		catch (NoSuchAlgorithmException e)
		{
			throw new IllegalArgumentException(e);
		}
	}
320625
public String hash(String key) {
        if (digester != null) {
            byte[] bytes = digester.digest(key.getBytes());
            return bytesToHexString(bytes);
        } else {
            return Integer.toHexString(key.hashCode());
        }
    }
1084659
public static function HmacString ($data, $key, $algo = self::DEFAULT_HASH_ALGORITHM) {
		return hash_hmac($algo, $data, $key, false);
	}
1265025
public static byte[] sumHmac(byte[] key, byte[] data)
    throws NoSuchAlgorithmException, InvalidKeyException {
    Mac mac = Mac.getInstance("HmacSHA256");

    mac.init(new SecretKeySpec(key, "HmacSHA256"));
    mac.update(data);

    return mac.doFinal();
  }
768867
@SuppressWarnings("unchecked")
	protected T init(String algorithm, PrivateKey privateKey, PublicKey publicKey) {
		this.algorithm = algorithm;

		if (null == privateKey && null == publicKey) {
			initKeys();
		} else {
			if (null != privateKey) {
				this.privateKey = privateKey;
			}
			if (null != publicKey) {
				this.publicKey = publicKey;
			}
		}
		return (T) this;
	}
1187779
public static byte[] digest(char[] plainBytes, byte[] salt, String algorithm, int iteration, int length) throws InvalidPasswordCipherException {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("algorithm : " + algorithm + " iteration : " + iteration);
            logger.fine("input length: " + plainBytes.length);
            logger.fine("salt length: " + salt.length);
            logger.fine("output length: " + length);
        }
        byte[] oBytes = null;

        if (plainBytes != null && plainBytes.length > 0 && algorithm != null && algorithm.length() > 0 && iteration > 0) {
            long begin = 0;
            if (logger.isLoggable(Level.FINE)) {
                begin = System.nanoTime();
            }
            try {
                SecretKeyFactory skf = SecretKeyFactory.getInstance(algorithm);
                PBEKeySpec ks = new PBEKeySpec(plainBytes, salt, iteration, length);
                SecretKey s = skf.generateSecret(ks);
                oBytes = s.getEncoded();
            } catch (Exception e) {
                throw (InvalidPasswordCipherException) new InvalidPasswordCipherException(e.getMessage()).initCause(e);
            }
            if (logger.isLoggable(Level.FINE)) {
                long elapsed = System.nanoTime() - begin;
                logger.fine("Elapsed time : " + elapsed + " ns " + (elapsed / 1000000) + " ms"); //debug
            }
        }

        if ((logger.isLoggable(Level.FINE)) && oBytes != null) {
            logger.fine("digest length: " + oBytes.length);
            logger.fine(hexDump(oBytes));
        }
        return oBytes;
    }
141529
public byte[] wrapKeyByKey(Key key,Key wrapKey)
	{
		try {
    		if(key==null ||wrapKey==null)
    		{
    			return null;
    		}
			Cipher cipher=Cipher.getInstance(algorithm);
			//使用私钥包裹模式
			cipher.init(Cipher.WRAP_MODE,wrapKey);
			return cipher.wrap(key);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
    	return null;
	}
54306
public static KeyFactory getKeyFactory(String algorithm) {
		final Provider provider = GlobalBouncyCastleProvider.INSTANCE.getProvider();

		KeyFactory keyFactory;
		try {
			keyFactory = (null == provider) //
					? KeyFactory.getInstance(getMainAlgorithm(algorithm)) //
					: KeyFactory.getInstance(getMainAlgorithm(algorithm), provider);
		} catch (NoSuchAlgorithmException e) {
			throw new CryptoException(e);
		}
		return keyFactory;
	}
184809
function(data, algorithm) {
    if (arguments.length === 1) {
      algorithm = 'md5';
    }
    return crypto.createHash(algorithm).update(data).digest('hex');
  }
909966
public static KeyPair generateKeyPair(String algorithm, AlgorithmParameterSpec params) {
		return KeyUtil.generateKeyPair(algorithm, params);
	}
1067124
public static PublicKey deserializePublicKey(byte[] keyData, String algorithm) {
        LOGGER.trace("deserialize public key from data using algorithm \"{}\"", algorithm);
        X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(keyData);
        try {
            KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
            return keyFactory.generatePublic(pubSpec);
        } catch (GeneralSecurityException e) {
            throw new IllegalArgumentException("provided data could not be converted to a PublicKey for algorithm "
                    + algorithm, e);
        }
    }
200671
static byte[] hmacSha1(StringBuilder message, String key) {
    try {
      Mac mac = Mac.getInstance("HmacSHA1");
      mac.init(new SecretKeySpec(key.getBytes(), "HmacSHA1"));
      return mac.doFinal(message.toString().getBytes());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
567409
public function validateHmac(string $hmac, string $key, string $algorithm = 'sha256', bool $raw = false): bool
	{
		return hash_equals($hmac, $this->getHmac($key, $algorithm, $raw));
	}
1251547
function hmac(data, key) {
  mctx.init(key);
  mctx.update(data);
  return mctx.finish();
}
845252
public function getHmac(string $key, string $algorithm = 'sha256', bool $raw = false): string
	{
		return hash_hmac_file($algorithm, $this->getPathname(), $key, $raw);
	}