Android MD5 Encode createHMACWithMD5(String source, String key)

Here you can find the source of createHMACWithMD5(String source, String key)

Description

create HMAC With MD

License

Open Source License

Declaration

public static String createHMACWithMD5(String source, String key)
            throws NoSuchAlgorithmException, InvalidKeyException 

Method Source Code

//package com.java2s;
/* //from w w w . j av  a2  s .co  m
 * SWRVE CONFIDENTIAL
 * 
 * (c) Copyright 2010-2014 Swrve New Media, Inc. and its licensors.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is and remains the property of Swrve
 * New Media, Inc or its licensors.  The intellectual property and technical
 * concepts contained herein are proprietary to Swrve New Media, Inc. or its
 * licensors and are protected by trade secret and/or copyright law.
 * Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Swrve.
 */

import android.util.Base64;

import java.security.InvalidKeyException;

import java.security.NoSuchAlgorithmException;

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

public class Main {
    public static String createHMACWithMD5(String source, String key)
            throws NoSuchAlgorithmException, InvalidKeyException {
        Mac hmac = Mac.getInstance("HmacMD5");
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(),
                hmac.getAlgorithm());
        hmac.init(secretKey);

        byte[] signature = hmac.doFinal(source.getBytes());
        return Base64.encodeToString(signature, Base64.DEFAULT);
    }
}

Related

  1. MD5(String text)
  2. stringGetMD5String(String s)
  3. byteMd5(String plainText, Boolean is16)
  4. getMD5(byte[] source)
  5. md5(String string)
  6. md5(String text)
  7. encryptByUsingMd5(String passwd)
  8. md5(String input)
  9. isValidMD5String(String md5String)