javaexceptionencryptionhttp-status-code-500jasypt

org.jasypt.exceptions.EncryptionOperationNotPossibleException throwing HTTP Status 500


I am checking if the String is not encrypted then display message but its throwing HTTP Status 500 – Internal Server Error as following:

org.jasypt.exceptions.EncryptionOperationNotPossibleException
    org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:1055)
    org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
    parvaz.aero.commons.security.Encryptor.decrypt(Encryptor.java:64)
    parvaz.aero.registration.staff.reset.ResetPassword.doGet(ResetPassword.java:34)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Here is how I checking either the String is encrypted or not

public static boolean isStringEncrypted(String str) {
    try {
        decrypt(str);
        return false;
    }catch(Exception e) {
        return true;
    }
}

Here I am trying to display my message if the String is not decrypted

        if(!isTokenNull) {
            String resetTokenEmail      = Encryptor.decrypt(resetToken);
            boolean isEmailEncrypted    = Encryptor.isStringEncrypted(resetTokenEmail);
        
            if(isEmailEncrypted) {
                String form = ChangePasswordForm.displayForm(resetToken,"","");
                out.println(SiteTemplate.webPage(form));
            }
            else {
                out.println(SiteTemplate.webPage(Message.getExpired()));
            }
        }
        else {
            out.println(SiteTemplate.webPage(Message.getExpired()));
        }

Despite showing Message.getExpired() why its throwing HTTP Status 500 – Internal Server Error?


Solution

  • I found that this error is thrown when:

    1. The String is already Encrypted
    2. When there is white space while encrypting or decrypting. So str.replaceAll(" ", "+"); and str.replaceAll("+", " "); fix this problem