001package 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 1852158 2019-01-25 18:19:46Z painter $ 030 */ 031public interface CryptoAlgorithm 032{ 033 /** 034 * Allows the user to set a salt value whenever the 035 * algorithm is used. Setting a new salt should invalidate 036 * all internal state of this object. 037 * <p> 038 * Algorithms that do not use a salt are allowed to ignore 039 * this parameter. 040 * <p> 041 * Algorithms must be able to deal with the null value as salt. 042 * They should treat it as "use a random salt". 043 * 044 * @param salt The salt value 045 * 046 */ 047 048 void setSeed(String salt); 049 050 /** 051 * Performs the actual encryption. 052 * 053 * @param value The value to be encrypted 054 * 055 * @return The encrypted value 056 * 057 * @throws Exception various errors from the underlying ciphers. 058 * The caller should catch them and report accordingly. 059 * 060 */ 061 062 String encrypt(String value) 063 throws Exception; 064 065 /** 066 * Algorithms that perform multiple ciphers get told 067 * with setCipher, which cipher to use. This should be 068 * called before any other method call. 069 * 070 * If called after any call to encrypt or setSeed, the 071 * CryptoAlgorithm may choose to ignore this or to reset 072 * and use the new cipher. 073 * 074 * If any other call is used before this, the algorithm 075 * should use a default cipher and not throw an error. 076 * 077 * @param cipher The cipher to use. 078 * 079 */ 080 081 void setCipher(String cipher); 082 083}