Problems with decrypt. Any Thoughts?

I am using encrypt and decrypt on my site. Encrypt works fine. When I decrypt I get the following error.

Lucee 5.0.0.254 Error (java.lang.ArrayIndexOutOfBoundsException)
Message 5
Cause   java.lang.ArrayIndexOutOfBoundsException
Stacktrace      The Error Occurred in
/home/jimsdailyawakenings/public_html/webdisplay.cfm: line 4
2: <cfset codetest = encrypt(thiscode, '123456')>
3: <cfoutput> #thiscode# - #codetest#</cfoutput>
4: <cfset codetest = decrypt( thiscode, '123456')>
5: <cfoutput> #thiscode# - #codetest#</cfoutput>
6: <cfabort>

Java Stacktrace lucee.runtime.exp.NativeException: 5
        at lucee.runtime.coder.UUCoder.decodeChars(UUCoder.java:119)
        at lucee.runtime.coder.UUCoder.decode(UUCoder.java:88)
        at lucee.runtime.coder.Coder.decode(Coder.java:62)
        at lucee.runtime.coder.Coder.decode(Coder.java:50)
        at lucee.runtime.functions.other.Decrypt.invoke(Decrypt.java:74)
        at lucee.runtime.functions.other.Decrypt.call(Decrypt.java:38)
        at webdisplay_cfm$cf.call(/home/jimsdailyawakenings/public_html/webdisplay.cfm:4)
        at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:863)
        at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:808)
        at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:803)
        at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:62)
        at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44)
        at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2250)
        at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2242)
        at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2210)
        at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:848)
        at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:103)
        at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:62).....

This is the code I have written…

<cfset thiscode = “works”>
<cfset codetest = encrypt(thiscode, ‘123456’)>
<cfoutput> #thiscode# - #codetest#</cfoutput>
<cfset codetest = decrypt( thiscode, ‘123456’)>
<cfoutput> #thiscode# - #codetest#</cfoutput>

Thank you

<cfset codetest = decrypt( thiscode, '123456')>

thiscode isn’t encrypted so decrypt can’t decrypt it.

Change it as follows (I changed your variable names so you can follow the path from plaintext to decrypted plaintext):

<cfset originalPlaintext = "works">
<cfset encryptedText = encrypt( originalPlaintext, '123456')>
<cfoutput>#originalPlaintext# - #encryptedText#</cfoutput>
<cfset decryptedPlainText = decrypt( encryptedText, '123456')>
<cfoutput>#originalPlaintext# - #decryptedPlainText#</cfoutput>

I am in idiot. Thank you!

We’ve all been there. More than once.

I see the error in the code you have pointed out @Juan_Aguilar, however, do you think that should cause the code to error? I feel like it would be more sensible for it to return a blank string or something to indicate it couldn’t decrypt it.