![JAR search and dependency download from the Maven repository](/logo.png)
de.mibos.commons.crypt.Padding 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 paddings for {@link Crypt}
*
* @author Michael Bock
* @version 1.5
* @since 1.4
* $Id: Padding.java 78 2014-10-08 20:00:18Z michaels-apps $
*/
public enum Padding {
/**
* PKCS5 padding
*/
PKCS5_PADDING("PKCS5Padding"),
/**
* No padding
*/
NO_PADDING("NoPadding");
/**
* PKCS5 Padding, the default algorithm for padding
*/
final public static Padding DEFAULT_PADDING_ALGORITHM = PKCS5_PADDING;
/**
* The shortcut used by the java API
*/
final private String shortcut;
/**
* Constructs a new padding
*
* @param shortcut the shortcut used by the java API
*/
Padding(final String shortcut) {
this.shortcut = shortcut;
}
/**
* @return the shortcut used by the java API
*/
@Nonnull
public String getShortcut() {
return shortcut;
}
/**
* Finds the Padding object for the given short cut
*
* @param shortcut the shortcut used by the java API
* @return the found padding
* @throws CryptoInitializationProblem if shortcut is unknown
*/
@Nonnull
static public Padding forShortcut(@Nonnull final String shortcut) {
for (Padding padding : Padding.values()) {
if (padding.getShortcut().equalsIgnoreCase(shortcut)) {
return padding;
}
}
throw new CryptoInitializationProblem("Unsupported padding " + shortcut);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy