Key Generator Mac : Key Generator « Security « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Security » Key GeneratorScreenshots 
Key Generator Mac
   
import java.security.Security;

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

public class MainClass {
  public static void main(String args[]) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    String inputString = "www.java2s.com";

    KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5");
    SecretKey secretKey = keyGen.generateKey();

    Mac mac = Mac.getInstance(secretKey.getAlgorithm());
    mac.init(secretKey);

    byte[] byteData = inputString.getBytes("UTF8");

    byte[] macBytes = mac.doFinal(byteData);

    String macAsString = new sun.misc.BASE64Encoder().encode(macBytes);

    System.out.println("Authentication code is: " + macAsString);
  }
}
           
         
    
    
  
KeyGeneratorMac.zip( 1,198 k)
Related examples in the same category
1.Using the KeyGenerator class and showing how to create a SecretKeySpec from an encoded key
2.Generate DSA key pair
3.KeyPair Generator For Private Key
4.KeyPair Generator For Public Key
5.Wrap And Unwrap Key
6.Generating a Public/Private Key Pair
7.Generate a 576-bit DH key pair
8.Generate a 1024-bit RSA key pair
9.Getting the Bytes of a Generated Key Pair
10.Get the bytes of the public and private keys
11.The bytes can be converted back to public and private key objects
12.Generate a key for the HMAC-SHA1 keyed-hashing algorithm
13.Asymmetric Key Maker
14.Generating a Symmetric Key
15.Xml dap Certs And Keys
16.Diffie-Hellman key exchange
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.