View Javadoc

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