Search in sources :

Example 6 with DecoderException

use of org.apache.commons.codec.DecoderException in project nifi by apache.

the class StringEncryptor method decryptPBE.

private byte[] decryptPBE(byte[] cipherBytes) throws DecoderException {
    PBECipherProvider pbecp = (PBECipherProvider) cipherProvider;
    final EncryptionMethod encryptionMethod = EncryptionMethod.forAlgorithm(algorithm);
    // Extract salt
    int saltLength = CipherUtility.getSaltLengthForAlgorithm(algorithm);
    byte[] salt = new byte[saltLength];
    System.arraycopy(cipherBytes, 0, salt, 0, saltLength);
    byte[] actualCipherBytes = Arrays.copyOfRange(cipherBytes, saltLength, cipherBytes.length);
    // Determine necessary key length
    int keyLength = CipherUtility.parseKeyLengthFromAlgorithm(algorithm);
    // Generate cipher
    try {
        Cipher cipher = pbecp.getCipher(encryptionMethod, new String(password.getPassword()), salt, keyLength, false);
        // Decrypt the plaintext
        return cipher.doFinal(actualCipherBytes);
    } catch (Exception e) {
        throw new EncryptionException("Could not decrypt sensitive value", e);
    }
}
Also used : EncryptionMethod(org.apache.nifi.security.util.EncryptionMethod) Cipher(javax.crypto.Cipher) DecoderException(org.apache.commons.codec.DecoderException) PBECipherProvider(org.apache.nifi.security.util.crypto.PBECipherProvider)

Example 7 with DecoderException

use of org.apache.commons.codec.DecoderException in project epadd by ePADD.

the class EmailUtils method printBodyAndAttachmentsToMbox.

private static void printBodyAndAttachmentsToMbox(String contents, EmailDocument ed, PrintWriter mbox, BlobStore blobStore) throws IOException {
    String frontier = "----=_Part_";
    List<Blob> attachments = null;
    if (ed != null)
        attachments = ed.attachments;
    boolean hasAttachments = !Util.nullOrEmpty(attachments) && blobStore != null;
    boolean isI18N = Util.isI18N(contents);
    if (!hasAttachments && !isI18N) {
        mbox.println();
        mbox.println(contents);
        mbox.println();
    } else {
        /*
			 * This is a multi-part message in MIME format.
			 * 
			 * ------=_Part_
			 * Content-Type: text/plain;
			 * charset="iso-8859-1"
			 * Content-Transfer-Encoding: 7bit
			 */
        // blank line
        mbox.println("Content-Type: multipart/mixed; boundary=\"" + frontier + "\"\n");
        // blank line
        mbox.println("This is a multi-part message in MIME format.\n");
        mbox.println("--" + frontier);
        mbox.println("Content-Type: text/plain; charset=\"UTF-8\"");
        // need blank line after this
        mbox.println("Content-Encoding: quoted-printable\n");
        try {
            byte[] encodedBytes = QuotedPrintableCodec.decodeQuotedPrintable(contents.getBytes());
            for (byte by : encodedBytes) mbox.print((char) by);
            mbox.println();
        } catch (DecoderException de) {
            log.warn("Exception trying to toString contents!" + de);
            mbox.println(contents);
            mbox.println();
        }
        // probably need to fix: other types of charset, encodings
        if (blobStore != null && attachments != null) {
            for (Blob b : attachments) {
                mbox.println("--" + frontier);
                mbox.println("Content-type: " + b.contentType);
                mbox.println("Content-transfer-encoding: base64");
                mbox.println("Content-Disposition: attachment;filename=\"" + b.filename + "\"\n");
                byte[] bytes = blobStore.getDataBytes(b);
                byte[] encodedBytes = Base64.encodeBase64(bytes, true);
                for (byte by : encodedBytes) mbox.print((char) by);
            }
            // note: the --frontier-- line is needed only at the very end, after all attachments -- NOT after each attachment.
            // this used to be a bug.
            mbox.println("--" + frontier + "--\n");
        }
    }
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) Blob(edu.stanford.muse.datacache.Blob)

Example 8 with DecoderException

use of org.apache.commons.codec.DecoderException in project cu-kfs by CU-CommunityApps.

the class WebUtils method sanitizeBackLocation.

public static String sanitizeBackLocation(String backLocation) {
    try {
        backLocation = urlCodec.decode(backLocation);
        Pattern pattern = Pattern.compile(ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.BACK_LOCATION_ALLOWED_REGEX));
        if (StringUtils.isNotEmpty(backLocation) && pattern.matcher(backLocation).matches()) {
            return HtmlUtils.htmlEscape(backLocation);
        }
    } catch (DecoderException de) {
        LOG.debug("Failed to decode backLocation: " + backLocation, de);
    }
    return ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.BACK_LOCATION_DEFAULT_URL);
}
Also used : Pattern(java.util.regex.Pattern) DecoderException(org.apache.commons.codec.DecoderException)

Example 9 with DecoderException

use of org.apache.commons.codec.DecoderException in project samourai-wallet-android by Samourai-Wallet.

the class CreateWalletActivity method initThread.

/**
 * Creates new wallet account
 *
 * @param create
 * @param pin
 * @param passphrase
 * @param seed
 */
private void initThread(final boolean create, final String pin, final String passphrase, final String seed) {
    toggleLoading();
    new Thread(new Runnable() {

        @Override
        public void run() {
            Looper.prepare();
            String guid = AccessFactory.getInstance(CreateWalletActivity.this).createGUID();
            String hash = AccessFactory.getInstance(CreateWalletActivity.this).getHash(guid, new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations);
            PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
            PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
            if (create) {
                try {
                    HD_WalletFactory.getInstance(CreateWalletActivity.this).newWallet(12, passphrase, SamouraiWallet.NB_ACCOUNTS);
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                } catch (MnemonicException.MnemonicLengthException mle) {
                    mle.printStackTrace();
                } finally {
                    ;
                }
            } else if (seed == null) {
                ;
            } else {
                try {
                    HD_WalletFactory.getInstance(CreateWalletActivity.this).restoreWallet(seed, passphrase, SamouraiWallet.NB_ACCOUNTS);
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                } catch (DecoderException de) {
                    de.printStackTrace();
                } catch (AddressFormatException afe) {
                    afe.printStackTrace();
                } catch (MnemonicException.MnemonicLengthException mle) {
                    mle.printStackTrace();
                } catch (MnemonicException.MnemonicChecksumException mce) {
                    mce.printStackTrace();
                } catch (MnemonicException.MnemonicWordException mwe) {
                    mwe.printStackTrace();
                } finally {
                    ;
                }
            }
            PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, true);
            try {
                String msg = null;
                if (HD_WalletFactory.getInstance(CreateWalletActivity.this).get() != null) {
                    if (create) {
                        msg = getString(R.string.wallet_created_ok);
                    } else {
                        msg = getString(R.string.wallet_restored_ok);
                    }
                    try {
                        AccessFactory.getInstance(CreateWalletActivity.this).setPIN(pin);
                        PayloadUtil.getInstance(CreateWalletActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(CreateWalletActivity.this).getGUID() + pin));
                        if (create) {
                            PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "new");
                            PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
                        } else {
                            PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "restored");
                            PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
                        }
                    } catch (JSONException je) {
                        je.printStackTrace();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    } catch (DecryptionException de) {
                        de.printStackTrace();
                    } finally {
                        ;
                    }
                    for (int i = 0; i < 2; i++) {
                        AddressFactory.getInstance().account2xpub().put(i, HD_WalletFactory.getInstance(CreateWalletActivity.this).get().getAccount(i).xpubstr());
                        AddressFactory.getInstance().xpub2account().put(HD_WalletFactory.getInstance(CreateWalletActivity.this).get().getAccount(i).xpubstr(), i);
                    }
                    // 
                    if (create) {
                        String seed = null;
                        try {
                            seed = HD_WalletFactory.getInstance(CreateWalletActivity.this).get().getMnemonic();
                        } catch (IOException ioe) {
                            ioe.printStackTrace();
                        } catch (MnemonicException.MnemonicLengthException mle) {
                            mle.printStackTrace();
                        }
                        Intent intent = new Intent(CreateWalletActivity.this, RecoveryWordsActivity.class);
                        intent.putExtra("BIP39_WORD_LIST", seed);
                        startActivity(intent);
                        finish();
                    } else {
                        AccessFactory.getInstance(CreateWalletActivity.this).setIsLoggedIn(true);
                        TimeOutUtil.getInstance().updatePin();
                        AppUtil.getInstance(CreateWalletActivity.this).restartApp();
                    }
                } else {
                    if (create) {
                        msg = getString(R.string.wallet_created_ko);
                    } else {
                        msg = getString(R.string.wallet_restored_ko);
                    }
                }
                Toast.makeText(CreateWalletActivity.this, msg, Toast.LENGTH_SHORT).show();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            } catch (MnemonicException.MnemonicLengthException mle) {
                mle.printStackTrace();
            } finally {
                ;
            }
            toggleLoading();
            Looper.loop();
        }
    }).start();
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONException(org.json.JSONException) Intent(android.content.Intent) IOException(java.io.IOException) DecoderException(org.apache.commons.codec.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Example 10 with DecoderException

use of org.apache.commons.codec.DecoderException in project samourai-wallet-android by Samourai-Wallet.

the class MainActivity2 method launchFromDialer.

private void launchFromDialer(final String pin) {
    if (progress != null && progress.isShowing()) {
        progress.dismiss();
        progress = null;
    }
    progress = new ProgressDialog(MainActivity2.this);
    progress.setCancelable(false);
    progress.setTitle(R.string.app_name);
    progress.setMessage(getString(R.string.please_wait));
    progress.show();
    new Thread(new Runnable() {

        @Override
        public void run() {
            Looper.prepare();
            try {
                PayloadUtil.getInstance(MainActivity2.this).restoreWalletfromJSON(new CharSequenceX(AccessFactory.getInstance(MainActivity2.this).getGUID() + pin));
                if (progress != null && progress.isShowing()) {
                    progress.dismiss();
                    progress = null;
                }
                AccessFactory.getInstance(MainActivity2.this).setIsLoggedIn(true);
                TimeOutUtil.getInstance().updatePin();
                AppUtil.getInstance(MainActivity2.this).restartApp();
            } catch (MnemonicException.MnemonicLengthException mle) {
                mle.printStackTrace();
            } catch (DecoderException de) {
                de.printStackTrace();
            } finally {
                if (progress != null && progress.isShowing()) {
                    progress.dismiss();
                    progress = null;
                }
            }
            Looper.loop();
        }
    }).start();
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) CharSequenceX(com.samourai.wallet.util.CharSequenceX) ProgressDialog(android.app.ProgressDialog)

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