We help IT Professionals succeed at work.
Get Started

When I encrypt/encode a string using codeigniter encryption class, it is different everytime, why?

parlays asked
Last Modified: 2012-05-09

I am using the codeigniter encryption class to encrypt card numbers that are stored in a database.

Here is the problem, if I encrypt say card number 823 and it produces 23wofj2398v, I can decrypt it and there is not problem I get back 823.  But if I encrypt it again I get xc9878dhjj (something different)...  it still decodes to 823.  But why do the two encryptions not produce the same result if I am using the same #.

Because I want to store the encrypted string in the database.  And later when someone searches for 823, I want to encrypt 823 again and search mysql for that encrypted string, but because it is producing different results, I can't search the database for that encrypted string.  Any suggestions how to get it to produce the same encrypted string?
Watch Question
Chief Technology Ninja
Distinguished Expert 2020
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE