0

I am Encrypting a string in c# and sending this to a php page like this.

sfplr.Attributes.Add("href", "http://sml.com.pk/a/sfpl/reports.php?id=" + Convert.ToBase64String(Encoding.Unicode.GetBytes(emailid)));

and the url genrated from this code is like this

http://sml.com.pk/a/sfpl/reports.php?id=bQBhAGwAaQBrAC4AYQBkAGUAZQBsAEAAcwBoAGEAawBhAHIAZwBhAG4AagAuAGMAbwBtAC4AcABrAA==

Now I want to decrypt again this bQBhAGwAaQBrAC4AYQBkAGUAZQBsAEAAcwBoAGEAawBhAHIAZwBhAG4AagAuAGMAbwBtAC4AcABrAA== in php o display in php page.Please any one help me to do this

2
  • 7
    Base64 encoding != encryption. Commented Nov 27, 2012 at 9:33
  • Malik, the email will not be encrypted, so you can send it as plain text (maybe with some url-encoding, so that it's safe to be put in an url) Commented Nov 27, 2012 at 9:39

3 Answers 3

2

Try using base64_decode function

Reference http://php.net/manual/en/function.base64-decode.php

In your case, it will be:

<?php    
    echo base64_decode($_GET['id']);
?>
Sign up to request clarification or add additional context in comments.

3 Comments

and how to get query string from asp.net page?
yes i Got Thanks and wait for 5 minutes to accepted ur answer
Again, note that base64 encoding is NOT encryption. And NEVER EVER transfer sensitive information over GET parameters. Not even over HTTPS.
2
$email =  base64_decode("bQBhAGwAaQBrAC4AYQBkAGUAZQBsAEAAcwBoAGEAawBhAHIAZwBhAG4AagAuAGMAbwBtAC4AcABrAA==");
echo $email;  //****** You will get email here... */

Please refer Is "convert.tobase64string" in .Net equal to "base64_encode" in PHP?

Comments

0

Using the base64_decode function will return the bytes you originally passed into the convert.toBase64String .

After that you'll have to retreive them in the following way :

<?php $emailBytes = base64_decode($_GET['id']); ?>

That will return, if it has been serialized correctly, the array you made in C# by using the Convert.toBase64String, see Encoding.getBytes.

Meaning, if the array is passed as you expected it to be (which I doubt)

$msg = "";
foreach ($emailBytes as $character) {
    $msg .= (char) $character;
}

I doubt you even need the Encoding.getBytes , you can just past a string as an argument.

In C# use

Convert.ToBase64String(emailid);

And then all you'd have to do in php is the retrieval in the way I first mentioned, that will give you the original passed String.

Also, as pointed out several times, that is an encryption you're performing, it's just making sure that it can be passed in the URL in a way no conflicts occur.

If you do want to encrypt, use a library on the C# side, encode the message, base64 encode it. Then on PHP side you'd have to do the reverse.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.