Here are my Encryptor class methods:
public String encrypt(String str){
if(str == null || str.equals("")){
str = "";
}
else{
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(mpCryptoPassword);
str = encryptor.encrypt(str);
}
return str;
}
public String decrypt(String str){
if(str == null || str.equals("")){
str = "";
}
else{
StandardPBEStringEncryptor decryptor = new StandardPBEStringEncryptor();
decryptor.setPassword(mpCryptoPassword);
str = decryptor.decrypt(str);
}
return str;
}
I am trying to encrypt as following:
String encryptedToken = "";
//preparing token email + time
Date now = new Date();
String prepareToken = "email="+email+"&tokenTime="+now.getTime();
//encrypt url value
Encryptor enc = new Encryptor();
encryptedToken = enc.encrypt(prepareToken);
and I am decrypting like:
Encryptor enc = new Encryptor();
String decryptedToken = enc.decrypt(encryptedToken);
Then its throwing error:
org.jasypt.exceptions.EncryptionOperationNotPossibleException at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:1055) at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725) at com.cryptography.Encryptor.decrypt(Encryptor.java:57) at com.users.forgot.ResetPassword.doGet(ResetPassword.java:72) at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at filters.charsetFilter.filter.CharsetFilter.doFilter(CharsetFilter.java:61) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:744)
Update
I noticed its working sometime but not working when there is + sign in the encrypted string as its getting + as space