KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > crypto > KeyGenerator

javax.crypto
Class KeyGenerator

java.lang.Object
  extended by javax.crypto.KeyGenerator
See Also:
Top Examples, Source Code, init, init, SecretKey

public final SecretKey generateKey()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final String getAlgorithm()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final KeyGenerator getInstance(String algorithm)
                                      throws NoSuchAlgorithmException
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1313]Generate a secret key, then serialize and DeSerialize an object with the key
By sunimals { at } hotmail { dot } com on 2005/02/19 23:46:26  Rate
/* 
 Written By  : Sunimal Senaratne 
  
  
 Description  :    1.  Generate a secret key 
           2.  Write into a saved serialize object  ( secret.key )  
           3.  DeSerialize the object  ( secret.key )  
  
  
 */
     
  
  
 import javax.crypto.KeyGenerator; 
 import javax.crypto.SecretKey; 
 import java.security.Key; 
 import java.io.*; 
  
  
 public class KeyGen implements Serializable  
  {    
   public static void main ( String [  ]  unused )  throws Exception  
    {  
     KeyGenerator kg = KeyGenerator.getInstance ( "HmacMD5" ) ; 
     kg.init ( 56 ) ;  
     SecretKey key1 = kg.generateKey (  ) ; 
      
   System.out.println ( "Generated Key:: " + key1 ) ; 
  
  
   FileOutputStream out = new FileOutputStream ( "secret.key" ) ; 
     ObjectOutputStream oOs1 = new ObjectOutputStream ( out ) ; 
     oOs1.writeObject ( key1 ) ; 
     oOs1.flush (  ) ; 
     oOs1.close (  ) ; 
  
  
   System.out.println ( "Serialize key into secret.key"+oOs1 ) ; 
  
  
   FileInputStream in = new FileInputStream ( "secret.key" ) ; 
     ObjectInputStream oOs2 = new ObjectInputStream ( in ) ; 
     SecretKey key2 =  ( SecretKey ) oOs2.readObject (  ) ; 
  
  
   System.out.println ( "DeSerialize key from secret.key"+key2 ) ; 
  
  
    }  
  }  
 


public static final KeyGenerator getInstance(String algorithm,
                                             String provider)
                                      throws NoSuchAlgorithmException,
                                             NoSuchProviderException
See Also:
IllegalArgumentException, NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final KeyGenerator getInstance(String algorithm,
                                             Provider provider)
                                      throws NoSuchAlgorithmException
See Also:
IllegalArgumentException, NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final Provider getProvider()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final void init(int keysize)
See Also:
InvalidParameterException, SecureRandom
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final void init(int keysize,
                       SecureRandom random)
See Also:
InvalidParameterException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final void init(SecureRandom random)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final void init(AlgorithmParameterSpec params)
                throws InvalidAlgorithmParameterException
See Also:
SecureRandom
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final void init(AlgorithmParameterSpec params,
                       SecureRandom random)
                throws InvalidAlgorithmParameterException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected KeyGenerator(KeyGeneratorSpi keyGenSpi,
                       Provider provider,
                       String algorithm)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags