LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-12-2010, 10:05 AM   #1
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Rep: Reputation: 38
Encryption from c client to php server?


hi,

I looking for an algoritm to encrypt some data sent from a c program(client) to a php server(can be in perl or cgi-bin) over the internet.

How should i send it in c? Some http call? Or it can be in via a perl script.

Then i need some basic algoritm to encrypt it. Any ideas. How do i save the key in the c program? Just something basic so its not clear text. This is not for a bank or visacards etc

Any idees? Thanks for any help or leeds.

Last edited by kalleanka; 01-12-2010 at 10:32 AM.
 
Old 01-13-2010, 02:49 AM   #2
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Original Poster
Rep: Reputation: 38
Cool

ok i found this: http://www.ficgs.com/How-to-crypt-an...ypt-s3141.html

and base64_encode and base64_decode does exist in PHP as in c.

Now i have to translate this to php and figure out how to handle the keys for different versions etc.

Happy programming!



How to crypt and decrypt ?

Every programmer at least once look for a good way to encrypt with the possibility to decrypt. Md5 and Sha1 are not convenient in this case as it is not possible to decrypt with these functions.

Here are nice functions that will help you to encrypt and decrypt with a key :

<?

function encrypt($string, $key)
{
$string = 'STT576PWZA'.$string;

$result = '';
for($i=0; $i<strlen($string); $i++)
{
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}

return base64_encode($result);
}

function decrypt($string, $key)
{
$result = '';
$string = base64_decode($string);

for($i=0; $i<strlen($string); $i++)
{
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}

$result = substr($result,10,strlen($result));

return $result;
}

?>


Note that here the string to encrypt is added to 10 characters, this may not be useful but it is just a way to add kind of salt.

It works fine anyway !
 
Old 01-13-2010, 11:13 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You might also want to look at gnutls, which can give you an encrypted session. It's pretty easy to use once you understand it, and TLS is also available for PHP (though I haven't used it.)
Kevin Barry
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssl using server and client certificate. Which key used for encryption? lievendp Linux - Security 2 12-07-2006 06:22 AM
LXer: PHP encryption for the common man LXer Syndicated Linux News 0 07-25-2006 06:54 PM
PHP GnuPG encryption/decryption rblampain Programming 5 08-12-2005 10:10 AM
Setting up a home web server with PHP, MySQL, and a mail client Kyle_D Linux - General 1 01-14-2005 01:52 AM
file up/download php client on linux server sam99 Programming 5 03-10-2004 05:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration