de.mibos.commons.crypt.BlockMode Maven / Gradle / Ivy
/*
* Copyright 2014 Michael Bock
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.mibos.commons.crypt;
import javax.annotation.Nonnull;
/**
* Supported block modes for {@link de.mibos.commons.crypt.Crypt}
*
* @author Michael Bock
* @version 1.5
* @since 1.4
* $Id: BlockMode.java 78 2014-10-08 20:00:18Z michaels-apps $
*/
public enum BlockMode {
/**
* Electronic code book mode
*/
ELECTRONIC_CODE_BOOK_MODE("ECB"),
/**
* Cipher block chain mode
*/
CIPHER_BLOCK_CHAIN_MODE("CBC"),
/**
* Cipher feedback mode
*/
CIPHER_FEEDBACK_MODE("CFB"),
/**
* Output feedback mode
*/
OUTPUT_FEEDBACK_MODE("OFB");
/**
* Cipher block chaining mode, the default algorithm for block chain mode
*/
final public static BlockMode DEFAULT_BLOCK_CHAIN_MODE = CIPHER_BLOCK_CHAIN_MODE;
/**
* The shortcut used by the java API
*/
final private String shortcut;
/**
* Constructs a new block mode
*
* @param shortcut the shortcut used by the java API
*/
BlockMode(final String shortcut) {
this.shortcut = shortcut;
}
/**
* @return the shortcut used by the java API
*/
@Nonnull
public String getShortcut() {
return shortcut;
}
/**
* Finds the BlockMode object for the given short cut
*
* @param shortcut the shortcut used by the java API
* @return the found block mode
* @throws de.mibos.commons.crypt.CryptoInitializationProblem if shortcut is unknown
*/
@Nonnull
static public BlockMode forShortcut(@Nonnull final String shortcut) {
for (BlockMode blockMode : BlockMode.values()) {
if (blockMode.getShortcut().equalsIgnoreCase(shortcut)) {
return blockMode;
}
}
throw new CryptoInitializationProblem("Unsupported block mode " + shortcut);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy