Java HMAC hmacSha1(String input, byte[] keyBytes)

Here you can find the source of hmacSha1(String input, byte[] keyBytes)

Description

hmac Sha

License

Apache License

Declaration

public static byte[] hmacSha1(String input, byte[] keyBytes) 

Method Source Code

//package com.java2s;
/**//  w  ww  .  j a v  a2  s  . c  om
 * Copyright (c) 2005-2010 wwinsoft.org.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * 
 * $Id: CryptoUtils.java 764 2009-12-27 19:13:59Z calvinxiu $
 */

import java.security.GeneralSecurityException;

import javax.crypto.Mac;
import javax.crypto.SecretKey;

import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static final String HMACSHA1 = "HmacSHA1";

    public static byte[] hmacSha1(String input, byte[] keyBytes) {
        try {
            SecretKey secretKey = new SecretKeySpec(keyBytes, HMACSHA1);
            Mac mac = Mac.getInstance(HMACSHA1);
            mac.init(secretKey);
            return mac.doFinal(input.getBytes());
        } catch (GeneralSecurityException e) {
            throw convertRuntimeException(e);
        }
    }

    private static IllegalStateException convertRuntimeException(GeneralSecurityException e) {
        return new IllegalStateException("Security exception", e);
    }
}

Related

  1. hmacSha1(byte[] secret, byte[] data)
  2. hmacSha1(SecretKey key, byte[] data)
  3. hmacSha1(SecretKeySpec signingKey, byte[]... data)
  4. hmacSha1(String data, String key)
  5. hmacSha1(String input, byte[] keyBytes)
  6. hmacSHA256(byte[] secret, byte[] data)
  7. hmacSha256(String keyHex, String stringData)
  8. hmacsha256Representation(String data, String pusherApplicationSecret)
  9. hmacSha512(byte[] key, byte[] message)