2 Replies - 7710 Views - Last Post: 06 June 2008 - 10:10 PM Rate Topic: -----

#1 Echilon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 23-February 07

C# to PHP Encryption

Post icon  Posted 06 June 2008 - 08: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?

Is This A Good Question/Topic? 0
  • +

Replies To: C# to PHP Encryption

#2 akozlik   User is offline

  • D.I.C Addict
  • member icon

Reputation: 92
  • View blog
  • Posts: 798
  • Joined: 25-February 08

Re: C# to PHP Encryption

Posted 06 June 2008 - 09:37 AM

View PostEchilon, on 6 Jun, 2008 - 11:48 AM, said:

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.
Was This Post Helpful? 0
  • +
  • -

#3 joeyadms   User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: C# to PHP Encryption

Posted 06 June 2008 - 10:10 PM

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....es_and_md5.aspx

PHP :
http://us3.php.net/m...pt.examples.php
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1