use of org.apache.commons.codec.DecoderException in project OpenAM by OpenRock.
the class AuthenticatorOATH method getAuthenticatorAppRegistrationUri.
private String getAuthenticatorAppRegistrationUri(OathDeviceSettings settings, AMIdentity id) throws AuthLoginException, IOException {
//check settings aren't null
if (settings == null) {
debug.error("OATH.checkOTP() : Invalid settings discovered.");
throw new AuthLoginException(amAuthOATH, "authFailed", null);
}
final AuthenticatorAppRegistrationURIBuilder builder = new AuthenticatorAppRegistrationURIBuilder(id, settings.getSharedSecret(), passLen, issuerName);
int algorithm = this.algorithm;
try {
if (algorithm == HOTP) {
int counter = settings.getCounter();
return builder.getAuthenticatorAppRegistrationUriForHOTP(counter);
} else if (algorithm == TOTP) {
return builder.getAuthenticatorAppRegistrationUriForTOTP(totpTimeStep);
} else {
debug.error("OATH .checkOTP() : No OTP algorithm selected");
throw new AuthLoginException(amAuthOATH, "authFailed", null);
}
} catch (DecoderException de) {
debug.error("OATH .getCreateQRDomElementJS() : Could not decode secret key from hex to plain text", de);
throw new AuthLoginException(amAuthOATH, "authFailed", null);
}
}
use of org.apache.commons.codec.DecoderException in project XobotOS by xamarin.
the class QuotedPrintableCodec method decodeQuotedPrintable.
/**
* Decodes an array quoted-printable characters into an array of original bytes. Escaped characters are converted
* back to their original representation.
*
* <p>
* This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in
* RFC 1521.
* </p>
*
* @param bytes
* array of quoted-printable characters
* @return array of original bytes
* @throws DecoderException
* Thrown if quoted-printable decoding is unsuccessful
*/
public static final byte[] decodeQuotedPrintable(byte[] bytes) throws DecoderException {
if (bytes == null) {
return null;
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int i = 0; i < bytes.length; i++) {
int b = bytes[i];
if (b == ESCAPE_CHAR) {
try {
int u = Character.digit((char) bytes[++i], 16);
int l = Character.digit((char) bytes[++i], 16);
if (u == -1 || l == -1) {
throw new DecoderException("Invalid quoted-printable encoding");
}
buffer.write((char) ((u << 4) + l));
} catch (ArrayIndexOutOfBoundsException e) {
throw new DecoderException("Invalid quoted-printable encoding");
}
} else {
buffer.write(b);
}
}
return buffer.toByteArray();
}
use of org.apache.commons.codec.DecoderException in project felix by apache.
the class CryptoServiceSingleton method generateAESKey.
/**
* Generate the AES key from the salt and the private key.
*
* @param salt the salt (hexadecimal)
* @param privateKey the private key
* @return the generated key.
*/
private SecretKey generateAESKey(String privateKey, String salt) {
try {
byte[] raw = Hex.decodeHex(salt.toCharArray());
KeySpec spec = new PBEKeySpec(privateKey.toCharArray(), raw, iterationCount, keySize);
SecretKeyFactory factory = SecretKeyFactory.getInstance(PBKDF_2_WITH_HMAC_SHA_1);
return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), AES_ECB_ALGORITHM);
} catch (DecoderException e) {
throw new IllegalStateException(e);
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
} catch (InvalidKeySpecException e) {
throw new IllegalStateException(e);
}
}
use of org.apache.commons.codec.DecoderException in project hale by halestudio.
the class FunctionContextProvider method getContext.
/**
* @see AbstractContextProvider#getContext(String, String)
*/
@Override
public IContext getContext(String contextId, String locale) {
// It is not possible to use dots (.) in the context id to identify the
// function, because it will be treated as part of the bundle name. So
// the function identifier is encoded using ONameUtil
int index = contextId.lastIndexOf('.');
String pluginId = contextId.substring(0, index);
String shortContextId = contextId.substring(index + 1);
if (pluginId.equals(PLUGIN_ID)) {
try {
String functionId = ONameUtil.decodeName(shortContextId);
FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, null);
if (function != null) {
FunctionTopic topic = new ContextFunctionTopic(function);
String description = function.getDescription();
if (description == null) {
description = function.getDisplayName();
}
return new SingleTopicContext(function.getDisplayName(), description, topic);
// XXX add more info to context (e.g. title?)
}
} catch (DecoderException e) {
// no valid function ID
}
}
return null;
}
use of org.apache.commons.codec.DecoderException in project nifi by apache.
the class ScryptCipherProvider method translateSalt.
/**
* Translates a salt from the mcrypt format {@code $n$r$p$salt_hex} to the Java scrypt format {@code $s0$params$saltBase64}.
*
* @param mcryptSalt the mcrypt-formatted salt string
* @return the formatted salt to use with Java Scrypt
*/
public String translateSalt(String mcryptSalt) {
if (StringUtils.isEmpty(mcryptSalt)) {
throw new IllegalArgumentException("Cannot translate empty salt");
}
// Format should be $n$r$p$saltHex
Matcher matcher = MCRYPT_SALT_FORMAT.matcher(mcryptSalt);
if (!matcher.matches()) {
throw new IllegalArgumentException("Salt is not valid mcrypt format of $n$r$p$saltHex");
}
String[] components = mcryptSalt.split("\\$");
try {
return Scrypt.formatSalt(Hex.decodeHex(components[4].toCharArray()), Integer.valueOf(components[1]), Integer.valueOf(components[2]), Integer.valueOf(components[3]));
} catch (DecoderException e) {
final String msg = "Mcrypt salt was not properly hex-encoded";
logger.warn(msg);
throw new IllegalArgumentException(msg);
}
}
Aggregations