View Javadoc

1   package org.apache.turbine.services.crypto;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  /***
20   * This interface describes the various Crypto Algorithms that are
21   * handed out by the Crypto Service.
22   *
23   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
24   * @version $Id: CryptoAlgorithm.java 264148 2005-08-29 14:21:04Z henning $
25   */
26  public interface CryptoAlgorithm
27  {
28      /***
29       * Allows the user to set a salt value whenever the
30       * algorithm is used. Setting a new salt should invalidate
31       * all internal state of this object.
32       * <p>
33       * Algorithms that do not use a salt are allowed to ignore
34       * this parameter.
35       * <p>
36       * Algorithms must be able to deal with the null value as salt.
37       * They should treat it as "use a random salt".
38       *
39       * @param salt      The salt value
40       */
41      void setSeed(String salt);
42  
43      /***
44       * Performs the actual encryption.
45       *
46       * @param value       The value to be encrypted
47       * @return The encrypted value
48       * @throws Exception various errors from the underlying ciphers.
49       *                   The caller should catch them and report accordingly.
50       */
51      String encrypt(String value)
52              throws Exception;
53  
54      /***
55       * Algorithms that perform multiple ciphers get told
56       * with setCipher, which cipher to use. This should be
57       * called before any other method call.
58       *
59       * If called after any call to encrypt or setSeed, the
60       * CryptoAlgorithm may choose to ignore this or to reset
61       * and use the new cipher.
62       *
63       * If any other call is used before this, the algorithm
64       * should use a default cipher and not throw an error.
65       *
66       * @param cipher    The cipher to use.
67       */
68      void setCipher(String cipher);
69  
70  }