Here you can find the source of createHMACWithMD5(String source, String key)
public static String createHMACWithMD5(String source, String key) throws NoSuchAlgorithmException, InvalidKeyException
//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); } }