1   /* $RCSfile: DESede3KeySecretKeyFactoryEngine.java,v $
2    * $Revision: 1.10 $
3    * $Date: 2003/10/04 19:18:38 $
4    * $Author: uwe_guenther $
5    * $State: Exp $
6    *
7    * Created on August 13, 2001 9:45 PM
8    *
9    * Copyright (C) 2001 Uwe Guenther <uwe@cscc.de>
10   *
11   * This file is part of the jhbci JCE-ServiceProvider. The jhbci JCE-
12   * ServiceProvider is a library, written in JavaTM, that should be 
13   * used in HBCI banking applications (clients and may be servers),
14   * to do cryptographic operations.
15   *
16   * The jhbci library is free software; you can redistribute it and/or
17   * modify it under the terms of the GNU Lesser General Public
18   * License as published by the Free Software Foundation; either
19   * version 2.1 of the License, or (at your option) any later version.
20   *
21   * The jhbci library is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24   * Lesser General Public License for more details.
25   *
26   * You should have received a copy of the GNU Lesser General Public
27   * License along with this library; if not, write to the Free Software
28   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29   *
30   */
31  
32  package de.cscc.crypto.provider;
33  
34  import java.security.InvalidKeyException;
35  import java.security.spec.InvalidKeySpecException;
36  import java.security.spec.KeySpec;
37  
38  import javax.crypto.SecretKey;
39  import javax.crypto.SecretKeyFactorySpi;
40  
41  /** 
42   * DESede3KeySecretKeyFactoryEngine Class.
43   *
44   * @author  <a href=mailto:uwe@cscc.de>Uwe G&uuml;nther</a>
45   * @version $Revision: 1.10 $
46   */
47  public final class DESede3KeySecretKeyFactoryEngine extends SecretKeyFactorySpi {
48      
49      /** The delegate for this wrapper object */
50      private DESede3KeySecretKeyFactoryImpl factory = 
51      new DESede3KeySecretKeyFactoryImpl();
52      
53      /** 
54       * Creates new DESede3KeySecretKeyFactoryEngine. 
55       *
56       * @throws SecurityException if the provider self integrity check fails.      
57       */
58      public DESede3KeySecretKeyFactoryEngine() {
59          if (JHBCI.selfIntegrityChecking() == false) {
60              throw new SecurityException("JHBCI-Provider is tampered.");
61          }      
62      }
63      
64      /** 
65       * Returns a string representation of the object.
66       *
67       * @return a string representation of the object.
68       */
69      public String toString() {
70          return this.factory.toString();
71      }    
72  
73      /** 
74       * Generates a <code>SecretKey</code> object from the
75       * provided key specification (key material).
76       *
77       * @param keySpec the specification (key material) of the secret key.
78       * @return the secret key.
79       * @exception InvalidKeySpecException if the given key specification
80       * is inappropriate for this secret-key factory to produce a secret key.
81       */
82      protected SecretKey engineGenerateSecret(KeySpec keySpec) 
83              throws InvalidKeySpecException {
84           return this.factory.generateSecret(keySpec);
85      }
86      
87      /** 
88       * Returns a specification (key material) of the given key object in the
89       * requested format.
90       *
91       * @param key the key.
92       * @param keySpec the requested format in which the key material shall be
93       * returned.
94       * @return the underlying key specification (key material) in the requested
95       * format.
96       * @throws NullPointerException if key or keySpec is null.
97       * @throws InvalidKeySpecException if the requested key specification is
98       * inappropriate for the given key (e.g., the algorithms associated with
99       * <code>key</code> and <code>keySpec</code> do not match, or
100      * <code>key</code> references a key on a cryptographic hardware device
101      * whereas <code>keySpec</code> is the specification of a software-based
102      * key), or the given key cannot be dealt with (e.g., the given key has
103      * an algorithm or format not supported by this secret-key factory).
104      */
105     protected KeySpec engineGetKeySpec(SecretKey key, Class keySpec) 
106             throws InvalidKeySpecException {
107         return this.factory.getKeySpec(key, keySpec);
108     }
109     
110     /** 
111      * Translates a key object, whose provider may be unknown or potentially
112      * untrusted, into a corresponding key object of this secret-key factory.
113      *
114      * @return they key whose provider is unknown or untrusted.
115      * @param key the key whose provider is unknown or untrusted.
116      * @throws NullPointerException if key is null.
117      * @throws InvalidKeyException if the given key cannot be processed by this
118      * secret-key factory.
119      */
120     protected SecretKey engineTranslateKey(SecretKey key) 
121             throws InvalidKeyException {
122         return this.factory.translateKey(key);
123     }
124 }
125