Skip to main content
Inspiring
July 7, 2008
Question

Encrypt giving different values when I reload

  • July 7, 2008
  • 2 replies
  • 392 views
On CF5, I am trying to encrypt a field. But for some reason, sometimes the last couple of characters changes. I run the page below... refresh a few times, and get different values. Ideas?

<cfset pswd = "VR4ds2dq">
<cfset key = "rwouwwrpi482kjdhjfhwurowwq">
<cfset passw = encrypt(pswd, key)>

<cfoutput>#passw#</cfoutput>

Thanks!
    This topic has been closed for replies.

    2 replies

    ltherAuthor
    Inspiring
    July 7, 2008
    Ah that all makes sense now. Thanks a lot!
    Participating Frequently
    July 7, 2008
    Expected, actually...

    The encrypt function doesn't guarantee that it will always produce the same ciphertext.
    It does guarantee, however, that the ciphertext will always correctly decrypt to the original value.

    I think you will find that decrypt(passw, key) will always produce "VR4ds2dq" - even though passw is sometimes different values.

    Depending on what you are trying to do, you might want to use the hash function. The hash function always produces the same output from the same input. The difference is that you cannot decrypt a hash. If you just want to check an entered password, hash will work fine for you. If you need to recover the original password, hash won't let you do this.

    -tom-