0

I want to encode my Url-params with Base64 and crypt(AES with CFB Mode), but it will not working and I can't get the error. Can someone help me? Here is my code:

    private String toBase64Crypt(String cryptString) {
    try {
        SecretKeySpec key = new SecretKeySpec(pwd.getBytes("UTF8"), "AES");

        byte[] cryptByte = cryptString.getBytes("UTF8"); 

        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        cryptString = Base64.encodeToString(cipher.doFinal(cryptByte),Base64.DEFAULT);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    }

    return cryptString;
}
MZaragoza
  • 10,108
  • 9
  • 71
  • 116
user3384194
  • 141
  • 1
  • 1
  • 11
  • If you are unable to see logcat, then you can run and debug that same code on the SE. I would say that you will get InvalidKeyException in the logs. – Oleg Estekhin Apr 15 '14 at 09:57
  • 1
    You really shouldn't be creating a key directly from a password like that. Look at http://stackoverflow.com/a/992413/474189 for example of how to use PBKDF2. – Duncan Jones Apr 15 '14 at 10:16
  • Adding to what Duncan and Oleg have said: For CFB you need a random IV for every message, otherwise either you encryption will fail or it will be insecure. Also I would generally advise the use of an authenticated encryption mode like GCM. – Perseids Apr 15 '14 at 12:16

0 Answers0