* do tipo {@link CipherType}.
*/
public static final Cipher getInstance(CipherType type)
throws InstantiateException {
if (type == null) {
throw new InstantiateException("O tipo passado e nulo");
}
Class<? extends Cipher> clazz = type.clazz;
if (clazz == null) {
throw new InstantiateException(Convert.toString(
"Tipo de codificador nao implementado: ", type.cipher));
}
Cipher instance = null;
try {
try {
Constructor<? extends Cipher> constructor;
constructor = clazz.getConstructor(CipherType.class);
instance = constructor.newInstance(type);
} catch (NoSuchMethodException e) {
instance = clazz.newInstance();
}
} catch (java.lang.InstantiationException e) {
throw new InstantiateException("Erro ao instanciar o codificador",e);
} catch (IllegalAccessException e) {
throw new InstantiateException("Erro ao acessar o codificador",e);
} catch (InvocationTargetException e) {
throw new InstantiateException("Erro ao construir o codificador",e);
} catch (Exception e) {
throw new InstantiateException(Convert.toString(
"Excecao desconhecida: ", e.getClass().getName(),
" -> ", e.getMessage()), e);
}
return instance;
}