1   /* $RCSfile: DES1KeySecretKeyFactoryEngine.java,v $
2    * $Revision: 1.9 $
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  /** 
43   * DES1KeySecretKeyFactoryEngine Class.
44   *
45   * @author  <a href=mailto:uwe@cscc.de>Uwe G&uuml;nther</a>
46   * @version $Revision: 1.9 $
47   */
48  public final class DES1KeySecretKeyFactoryEngine extends SecretKeyFactorySpi {
49  
50      /** The delegate for this wrapper object */
51      private DES1KeySecretKeyFactoryImpl factory = 
52      new DES1KeySecretKeyFactoryImpl();
53      
54      /** 
55       * Creates new DES1KeySecretKeyFactoryEngine. 
56       *
57       * @throws SecurityException if the provider self integrity check fails.     
58       */
59      public DES1KeySecretKeyFactoryEngine() {
60          if (JHBCI.selfIntegrityChecking() == false) {
61              throw new SecurityException("JHBCI-Provider is tampered.");
62          }            
63      }
64      
65      /** 
66       * Returns a string representation of the object.
67       *
68       * @return a string representation of the object.
69       */
70      public String toString() {
71          return this.factory.toString();
72      }        
73  
74      /** 
75       * Generates a <code>SecretKey</code> object from the
76       * provided key specification (key material).
77       *
78       * @param keySpec the specification (key material) of the secret key.
79       * @return the secret key.
80       * @throws NullPointerException if keySpec is null.
81       * @throws InvalidKeySpecException if the given key specification
82       * is inappropriate for this secret-key factory to produce a secret key.
83       */
84      protected SecretKey engineGenerateSecret(KeySpec keySpec) 
85              throws InvalidKeySpecException {
86           return this.factory.generateSecret(keySpec);
87      }
88      
89      
90      /** 
91       * Returns a specification (key material) of the given key object in the
92       * requested format.
93       *
94       * @param key the key.
95       * @param keySpec the requested format in which the key material shall be
96       * returned.
97       * @return the underlying key specification (key material) in the requested
98       * format.
99       * @throws NullPointerException if key or keySpec is null.
100      * @throws InvalidKeySpecException if the requested key specification is
101      * inappropriate for the given key (e.g., the algorithms associated with
102      * <code>key</code> and <code>keySpec</code> do not match, or
103      * <code>key</code> references a key on a cryptographic hardware device
104      * whereas <code>keySpec</code> is the specification of a software-based
105      * key), or the given key cannot be dealt with (e.g., the given key has
106      * an algorithm or format not supported by this secret-key factory).
107      */
108     protected KeySpec engineGetKeySpec(SecretKey key, Class keySpec) 
109             throws InvalidKeySpecException {
110         return this.factory.getKeySpec(key, keySpec);
111     }    
112     
113     /** 
114      * Translates a key object, whose provider may be unknown or potentially
115      * untrusted, into a corresponding key object of this secret-key factory.
116      *
117      * @return they key whose provider is unknown or untrusted.
118      * @param key the key whose provider is unknown or untrusted.
119      * @throws NullPointerException if key is null.
120      * @throws InvalidKeyException if the given key cannot be processed by this
121      * secret-key factory.
122      */
123     protected SecretKey engineTranslateKey(SecretKey key) 
124     throws InvalidKeyException {
125         return this.factory.translateKey(key);
126     }
127     
128 }
129