MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

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

public class MainClass {
    public static void main(String[] args) throws Exception {
        String alg = "HmacMD5";
        Mac mac = Mac.getInstance(alg);
        KeyGenerator kg = KeyGenerator.getInstance(alg);
        SecretKey key = kg.generateKey();
        mac.init(key);
        mac.update("test".getBytes());
        byte[] b = mac.doFinal();
        System.out.println(new String(b));

    }
}