001    package org.apache.fulcrum.crypto;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    /**
025     * This interface describes the various Crypto Algorithms that are
026     * handed out by the Crypto Service.
027     *
028     * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
029     * @version $Id: CryptoAlgorithm.java 535465 2007-05-05 06:58:06Z tv $
030     */
031    
032    public interface CryptoAlgorithm
033    {
034        /**
035         * Allows the user to set a salt value whenever the
036         * algorithm is used. Setting a new salt should invalidate
037         * all internal state of this object.
038         * <p>
039         * Algorithms that do not use a salt are allowed to ignore
040         * this parameter.
041         * <p>
042         * Algorithms must be able to deal with the null value as salt.
043         * They should treat it as "use a random salt".
044         *
045         * @param salt      The salt value
046         *
047         */
048    
049        void setSeed(String salt);
050    
051        /**
052         * Performs the actual encryption.
053         *
054         * @param value       The value to be encrypted
055         *
056         * @return The encrypted value
057         *
058         * @throws Exception various errors from the underlying ciphers.
059         *                   The caller should catch them and report accordingly.
060         *
061         */
062    
063        String encrypt(String value)
064            throws Exception;
065    
066        /**
067         * Algorithms that perform multiple ciphers get told
068         * with setCipher, which cipher to use. This should be
069         * called before any other method call.
070         *
071         * If called after any call to encrypt or setSeed, the
072         * CryptoAlgorithm may choose to ignore this or to reset
073         * and use the new cipher.
074         *
075         * If any other call is used before this, the algorithm
076         * should use a default cipher and not throw an error.
077         *
078         * @param cipher    The cipher to use.
079         *
080         */
081    
082        void setCipher(String cipher);
083    
084    }