SecretKeyFactory


SecretKeyFactory javax.crypto

Java 1.4

This class defines an API for translating a secret key between its opaque SecretKey representation and its transparent javax.crypto.SecretKeySpec representation. It is much like java.security.KeyFactory , except that it works with secret (or symmetric) keys rather than with public and private (asymmetric) keys. SecretKeyFactory is algorithm-independent and provider-based, so you must obtain a SecretKeyFactory object by calling one of the static getInstance( ) factory methods and specifying the name of the desired secret-key algorithm and, optionally , the name of the provider whose implementation is desired. In Java 5.0, the "SunJCE" provider provides SecretKeyFactory implementations for algorithms with the following names :

DES

DESede

PBE

PBEWithMD5AndDES

PBEWithMD5AndTripleDES

PBEWithSHA1AndDESede

PBEWithSHA1AndRC2

   

Once you have obtained a SecretKeyFactory , use generateSecret( ) to create a SecretKey from a java.security.spec.KeySpec (or its subclass, javax.crypto.spec.SecretKeySpec ). Or call getKeySpec( ) to obtain a KeySpec for a Key object. Because there can be more than one suitable type of KeySpec , getKeySpec( ) requires a Class object to specify the type of the KeySpec to be created. See also DESKeySpec , DESedeKeySpec , and PBEKeySpec in the javax.crypto.spec package.

 public class  SecretKeyFactory  {  // Protected Constructors  protected  SecretKeyFactory  (SecretKeyFactorySpi  keyFacSpi  ,          java.security.Provider  provider  , String  algorithm  );  // Public Class Methods  public static final SecretKeyFactory  getInstance  (String  algorithm  )          throws java.security.NoSuchAlgorithmException;        public static final SecretKeyFactory  getInstance  (String  algorithm  ,          java.security.Provider  provider  )          throws java.security.NoSuchAlgorithmException;        public static final SecretKeyFactory  getInstance  (String  algorithm  ,          String  provider  ) throws java.security.NoSuchAlgorithmException,          java.security.NoSuchProviderException;  // Public Instance Methods  public final SecretKey  generateSecret  (java.security.spec.KeySpec  keySpec  )          throws java.security.spec.InvalidKeySpecException;        public final String  getAlgorithm  ( );        public final java.security.spec.KeySpec  getKeySpec  (SecretKey  key  , Class  keySpec  )          throws java.security.spec.InvalidKeySpecException;        public final java.security.Provider  getProvider  ( );        public final SecretKey  translateKey  (SecretKey  key  )          throws java.security.InvalidKeyException;   } 



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net