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 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(
        at lucee.runtime.coder.UUCoder.decode(
        at lucee.runtime.coder.Coder.decode(
        at lucee.runtime.coder.Coder.decode(
        at lucee.runtime.functions.other.Decrypt.invoke(
        at webdisplay_cfm$
        at lucee.runtime.PageContextImpl._doInclude(
        at lucee.runtime.PageContextImpl.doInclude(
        at lucee.runtime.PageContextImpl.doInclude(
        at lucee.runtime.listener.ClassicAppListener._onRequest(
        at lucee.runtime.listener.MixedAppListener.onRequest(
        at lucee.runtime.PageContextImpl.execute(
        at lucee.runtime.PageContextImpl._execute(
        at lucee.runtime.PageContextImpl.executeCFML(
        at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(
        at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(
        at lucee.loader.servlet.CFMLServlet.service(

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.