scottyab / AESCrypt-Android

Simple API to perform AES encryption on Android. This is the Android counterpart to the AESCrypt library Ruby and Obj-C (with the same weak security defaults :( ) created by Gurpartap Singh. https://github.com/Gurpartap/aescrypt
Apache License 2.0
641 stars 191 forks source link

Crashing if invalid BASE64 String Given #13

Closed dynamitechetan closed 8 years ago

dynamitechetan commented 8 years ago

java.lang.IllegalArgumentException: bad base-64

in this line :
byte[] decodedCipherText = Base64.decode(base64EncodedCipherText, Base64.NO_WRAP);

This occurs when base64EncodedCipherText is not a proper BASE64 value . Write something to check for a proper BASE64 and then pass it to the function.

dynamitechetan commented 8 years ago

I figured it out ...

 String pattern = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
                            Pattern r = Pattern.compile(pattern);
                            Matcher m = r.matcher(msg);
                            if (m.find()) {
                                encryptedMsg = AESCrypt.decrypt(pass, msg);

                            } else {
                                encryptedMsg = "Error Decrypting...Please try again";
                            }