View Javadoc

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