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

  • Home
  • SEARCH
  • 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 7866623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:27:19+00:00 2026-06-03T00:27:19+00:00

this really has me stumped…. I’m messing around with encryption using PHP. Using memory,

  • 0

this really has me stumped….

I’m messing around with encryption using PHP.

Using memory, everything is fine….

//encrypt the sensitive data
$encryptedData = encrypt($senstiveData, $theKey);

//decrypt the data
$decryptedData = decrypt($encryptedData, $theKey);

//print decrypted string
echo "<br>Decrypted String:" . $decryptedData;

i.e. the decrypted string: contains the correct value.

However, if I write the information out to file.. it breaks.

$orderFile = "orders.dat";
$fh = fopen($orderFile, 'a') or die("can't open file");
fwrite($fh, $keyCode . "\n");
$serializedArray = serialize($encryptedData); 
fwrite($fh, $serializedArray . "\n");
fclose($fh);

$file = fopen("orders.dat","r");

//key is first line in 'orders.dat'
$theKey = fgets($file);

//serialised array is second line...
$unserializedArray = unserialize(fgets($file));

$decryptedData2 = decrypt($unserializedArray, $theKey);

//print decrypted string
echo "<br>Decrypted String:" . $decryptedData2 . "<br>";

And… the answer is incorrect.

I’ve verified that the key and array used in both versions are identical (i.e. the reconstructed unserialized array contains the same values as before it was serialized), could something be getting lost in translation when I write to file?

Any ideas where I should start looking to debug this?

Any advice would be appreciated,
Mitch.

  • 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-06-03T00:27:21+00:00Added an answer on June 3, 2026 at 12:27 am

    Remove the new-line character(s) from your fwrite(). I.e., don’t do this:

    fwrite($fh, $keyCode . "\n");
    

    The \n can screw up the encryption/decryption routines.

    This should be adequate:

    fwrite($fh, $keyCode);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really stumped by this one! The StackFrame object ( MSDN Link ) has
I'm new to javascript/jQuery this really has me stumped. What I'm trying to achieve
This one really has me stumped. I have a documents table which hold info
Ok, I really spend 2 days on this and it has gotten me stumped.
I know this topic has been beaten into the ground, but I'm really stumped.
This really has my stumped today. I'm sure its simple, but... Here is my
quick question really that has me momentarily stumped. This program searches through a a
This one really has me stumped. I have not ran across this problem on
This one has really got me stumped. I have certain forms that are being
I've been having this really annoying thing happen the past few days, that has

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.