Java HMAC hmacSha(byte[] keyBytes, byte[] text)

Here you can find the source of hmacSha(byte[] keyBytes, byte[] text)

Description

hmac Sha

License

Open Source License

Declaration

private static byte[] hmacSha(byte[] keyBytes, byte[] text) 

Method Source Code

//package com.java2s;
/*//from   w  w w.  j  a  v  a2  s  .  co m
 * #%L
 * ORTOLANG
 * A online network structure for hosting language resources and tools.
 * 
 * Jean-Marie Pierrel / ATILF UMR 7118 - CNRS / Universit? de Lorraine
 * Etienne Petitjean / ATILF UMR 7118 - CNRS
 * J?r?me Blanchard / ATILF UMR 7118 - CNRS
 * Bertrand Gaiffe / ATILF UMR 7118 - CNRS
 * Cyril Pestel / ATILF UMR 7118 - CNRS
 * Marie Tonnelier / ATILF UMR 7118 - CNRS
 * Ulrike Fleury / ATILF UMR 7118 - CNRS
 * Fr?d?ric Pierre / ATILF UMR 7118 - CNRS
 * C?line Moro / ATILF UMR 7118 - CNRS
 *  
 * This work is based on work done in the equipex ORTOLANG (http://www.ortolang.fr/), by several Ortolang contributors (mainly CNRTL and SLDR)
 * ORTOLANG is funded by the French State program "Investissements d'Avenir" ANR-11-EQPX-0032
 * %%
 * Copyright (C) 2013 - 2015 Ortolang Team
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
 * #L%
 */

import java.lang.reflect.UndeclaredThrowableException;

import java.security.GeneralSecurityException;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static byte[] hmacSha(byte[] keyBytes, byte[] text) {
        try {
            Mac hmac;
            hmac = Mac.getInstance("HmacSHA1");
            SecretKeySpec macKey = new SecretKeySpec(keyBytes, "RAW");
            hmac.init(macKey);
            return hmac.doFinal(text);
        } catch (GeneralSecurityException gse) {
            throw new UndeclaredThrowableException(gse);
        }
    }
}

Related

  1. hmac_sha(String crypto, byte[] keyBytes, byte[] text)
  2. hmac_sha(String crypto, byte[] keyBytes, byte[] text)
  3. hmacDigest(String message, String secretKey, String algorithm)
  4. hmacEncode(String algorithm, String input, String privateKey)
  5. hmacHex(String keyString, String message, String hmac)
  6. hmacSha(String crypto, String key, String value)
  7. hmacSha1(byte[] data, byte[] key)
  8. hmacSha1(byte[] key_bytes, byte[] text_bytes)
  9. hmacSha1(byte[] secret, byte[] data)