init HmacMD5 Key - Java Security

Java examples for Security:HMAC

Description

init HmacMD5 Key

Demo Code


//package com.java2s;

import javax.crypto.KeyGenerator;

import javax.crypto.SecretKey;

import sun.misc.BASE64Encoder;

public class Main {

    public static final String KEY_MAC = "HmacMD5";

    public static String initMacKey() throws Exception {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_MAC);
        SecretKey secretKey = keyGenerator.generateKey();
        return encryptBASE64(secretKey.getEncoded());
    }/*www. j a  v a 2 s  .c om*/

    public static String encryptBASE64(byte[] key) throws Exception {
        return (new BASE64Encoder()).encodeBuffer(key);
    }
}

Related Tutorials