Note that there are some explanatory texts on larger screens.

plurals
  1. POOdd format of Message Authentication Code output
    primarykey
    data
    text
    <p>I'm running an example from an IBM tutorial which has a simple example to generate a MAC on given plain text. The code is as follows:</p> <pre><code>public static void main(String[] args) throws Exception { // // check args and get plaintext if (args.length != 1) { System.err .println("Usage: java MessageAuthenticationCodeExample text"); System.exit(1); } byte[] plainText = args[0].getBytes("UTF8"); // // get a key for the HmacMD5 algorithm System.out.println("\nStart generating key"); KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5"); SecretKey MD5key = keyGen.generateKey(); System.out.println("Finish generating key"); // // get a MAC object and update it with the plaintext Mac mac = Mac.getInstance("HmacMD5"); mac.init(MD5key); mac.update(plainText); // // print out the provider used and the MAC System.out.println("\n" + mac.getProvider().getInfo()); System.out.println("\nMAC: "); System.out.println(new String(mac.doFinal(), "UTF8")); } </code></pre> <p>That's all good but running it with the String arg "This is a test" I get the following output:</p> <p><img src="https://i.stack.imgur.com/pF4gx.png" alt="enter image description here"></p> <p>In the actual tutorial the MAC output is formatted much more nicely as e.g.</p> <pre><code> MAC: Dkdj47x4#.@kd#n8a-x&gt; </code></pre> <p>, by nicely I mean characters that I actually recognize! </p> <p>I thought the use of "UTF8" parameter served this purpose but I have probably got it wrong so can anyone tell me how I get the output to format like above?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload