Search in sources :

Example 1 with DecoderException

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);
    }
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException)

Example 2 with DecoderException

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();
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with DecoderException

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);
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) DecoderException(org.apache.commons.codec.DecoderException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) SecretKeySpec(javax.crypto.spec.SecretKeySpec) KeySpec(java.security.spec.KeySpec) PBEKeySpec(javax.crypto.spec.PBEKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 4 with DecoderException

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;
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) SingleTopicContext(eu.esdihumboldt.hale.doc.util.context.SingleTopicContext) FunctionTopic(eu.esdihumboldt.cst.doc.functions.internal.toc.FunctionTopic)

Example 5 with DecoderException

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);
    }
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) Matcher(java.util.regex.Matcher)

Aggregations

DecoderException (org.apache.commons.codec.DecoderException)41 IOException (java.io.IOException)16 CharSequenceX (com.samourai.wallet.util.CharSequenceX)8 MnemonicException (org.bitcoinj.crypto.MnemonicException)8 JSONException (org.json.JSONException)7 DecryptionException (com.samourai.wallet.crypto.DecryptionException)6 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 ProgressDialog (android.app.ProgressDialog)4 HD_Wallet (com.samourai.wallet.hd.HD_Wallet)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HashMap (java.util.HashMap)4 List (java.util.List)4 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 ByteBuffer (java.nio.ByteBuffer)3 Map (java.util.Map)3 Cipher (javax.crypto.Cipher)3 AddressFormatException (org.bitcoinj.core.AddressFormatException)3