Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 461931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:01:27+00:00 2026-05-12T23:01:27+00:00

I was attempting to encrypt de cookie data with md5, but I can not

  • 0

I was attempting to
encrypt de cookie data with md5, but I can not validate the hash back.

It has got to do, with the fact that cookie_data is a serialized array, because normal stringvalues work ok.

It’s actually from a codeigniter class, but it does not work??
Does anyone know what the problem might be?

$hash    = substr($session, strlen($session)-32); 
$session= substr($session, 0, strlen($session)-32); 

if ($hash !==  md5($session.$this->encrypt_key))
{........

and the cookie value is encrypted like this

$cookie_data = $cookie_data.md5($cookie_data.$this->encrypt_key);

EDIT
I found that the answer is to use urlencode en urldecode in the proces of creating and validate
md5 hashes, because setcookie does urlencode automaticly, and thereby possibly changing the hash.

thanks, Richard

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:01:27+00:00Added an answer on May 12, 2026 at 11:01 pm

    md5 is a oneway function. It is not a reversible one, so you can’t decrypt the data.

    The only thing you can do is encrypt the original data (if you saved it elsewhere) and check the result of this second computation.

    If the value retrieved and the new value calculated are the same, the hash you received is valid (As you are doing in your code).

    EDIT

    You know, with just three lines of code I will guess some possible causes:

    1. $session doesn’t contains at the beginning of your code the same value of cookie_data.
    2. you are using multibyte strings and strlen is not mb aware (use the idioms substr($session,0,-32) to get the payload part of the string.
    3. maybe substr doesn’t cope with multibyte strings too, use explicitally mb_substr (or whatever it is called).

    To me the first case is the more probable. For what I can see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to encrypt a file that will be deployed with an application
I need to use a Delphi component to encrypt a file that can then
I'm attempting to use symmetric encryption to encrypt some data, and store the key
Attempting to take the data in my gridview and convert it back into a
Attempting to set up an automated texting service for customers, where people can text
Attempting to use the data series from this example no longer passes the JSONLint
Attempting to make a NSObject called 'Person' that will hold the login details for
Attempting to build a C# project which has numerous references to assemblies in NuGet
Attempting to test whether a post has a 'main_slider', 'flickr-slider', or 'video-slider' value. 'main_slider'
Attempting to use the amazon API to obtain product data and currently failing miserably.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.