Avatar of Chipkin_com
Chipkin_com
 asked on

php mcrypt_encrypt to C/C++/MFC equalivilent

Hello
I have a PHP script that generates a product key for an application written in c++/MFC. The product key is email to the user and the user copy and pasts it in to my application.
I'm looking for a way to decoded the output of the php function in C++/MFC.

I have looked in to http://mcrypt.sourceforge.net/ but its too advanced for me

// PHP code 
function EncryptData( $data ) {
$key  = "abcdefghijklmnopqrstuvwxyz";
// This encrypt method is described here 
// http://ca3.php.net/mcrypt
$val     = $data ; 
$ky      = $key ; 
$mode    = MCRYPT_MODE_ECB;   
$enc     = MCRYPT_RIJNDAEL_128;
$val     = str_pad($val, (16*(floor(strlen($val) / 16)+(strlen($val) % 16==0?2:1))), chr(16-(strlen($val) % 16)));
$encript = mcrypt_encrypt($enc, $ky, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM));
$hex     = bin2hex( $encript ) ;
$ret     = strtoupper( $hex );
return $ret; }

Open in new window

Editors IDEsC

Avatar of undefined
Last Comment
CSecurity

8/22/2022 - Mon
CSecurity

well, you can code it yourself. but you told that "it's so advanced for me"
so, i suggest you write a php page that gives some parameters (data) and then takes the result. so, your MFC application can send data using HTTP POST method to send encrypted data and your php should give back decoded data to MFC data.
yours sincerely
Chipkin_com

ASKER
Uhm no.
Why would I encrypt it in the first place if I'm then going to turn around a send it plain text (over the wire) once the user receives it. I don't want the users to know what is inside the encrypted data.

I was hoping not to have to code the function myself.
I'm surprised that this hasn't been done before unless everyone is using the  http://mcrypt.sourceforge.net/ library and that seems unlikely.
Chipkin_com

ASKER
FYI found an answer to my question.
http://www.codeproject.com/KB/security/aes.aspx
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
CSecurity

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CSecurity

oh! sorry, forgot to tell
RC4 is some nice algorithm because encryption and decryption algorithms are the same. lemme make it more clear. if you encrypt some data using rc4 algorithm using some password and then want to decrypt it, you should decrypt it as if you want encrypt it.
regards