Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,685 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,251 people online right now. Registration is fast and FREE... Join Now!




C# to PHP Encryption

 
Reply to this topicStart new topic

C# to PHP Encryption

Echilon
post 6 Jun, 2008 - 07:48 AM
Post #1


New D.I.C Head

*
Joined: 23 Feb, 2007
Posts: 12


My Contributions


I have a program written in C#, and a file in PHP. I need to be able to load information from the PHP file to use in my application. As it happens, the information will contain the database connection details which the PHP script has access to.

I know I could just echo these in PHP, then read them using C#, but I need a more secure method really to prevent anyone from just loading the PHP script in a browser and reading the database credentials.

I'm not an expert in encryption, but I'm fairly confident in both languages. I'm just not sure how to encrypt something with a key in one language, then decrypt it with another. Can anyone point me in the right direction?
User is offlineProfile CardPM

Go to the top of the page

akozlik
post 6 Jun, 2008 - 08:37 AM
Post #2


D.I.C Addict

Group Icon
Joined: 25 Feb, 2008
Posts: 596



Thanked 22 times

Dream Kudos: 750
My Contributions


QUOTE(Echilon @ 6 Jun, 2008 - 11:48 AM) *

I have a program written in C#, and a file in PHP. I need to be able to load information from the PHP file to use in my application. As it happens, the information will contain the database connection details which the PHP script has access to.

I know I could just echo these in PHP, then read them using C#, but I need a more secure method really to prevent anyone from just loading the PHP script in a browser and reading the database credentials.

I'm not an expert in encryption, but I'm fairly confident in both languages. I'm just not sure how to encrypt something with a key in one language, then decrypt it with another. Can anyone point me in the right direction?


You could write a script that analyzes the database in PHP and outputs the resulting database calls to XML. Your C# program could then just read the XML file. After it's finished reading, it could just destroy the file.

I don't know if that's what you're looking for, but it's an option. I wrote a tutorial in the PHP Tutorial section about how to get your database to be XML. Check it out if you're interested.
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 6 Jun, 2008 - 09:10 PM
Post #3


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600

Expert In: PHP, Web Security

My Contributions


The best way to to pass this safely, is using TrippleDES encryption. You could have the values output inside XML, or just delimited by some special character like data:data:data

Basically you take a key you create, 256 bit, and hardcode it into both your C# and PHP app, and use mcrypt in PHP to encrypt data, and some functions in C# to decrypt.

Here are some links for PHP mcrypt, and C# decryption functions to get you going.

C# : http://www.csharper.net/blog/library_encry...es_and_md5.aspx

PHP :
http://us3.php.net/manual/en/mcrypt.examples.php


User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:00AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month