Link to home
Start Free TrialLog in
Avatar of eddysusanto
eddysusanto

asked on

Encryption Library for VB and PHP

Dear member,
Can you suggest me a strong encryption library that I can use for VB and PHP ?

I need to encrypt and decrypt text. Encryption and decryption must can be done from VB6.0 application and PHP website.
And cross process. Encrypt using VB and decrypt using PHP and otherwise.
I dont want to use .net

I dont mind a premium library or a free one.

Thank you.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

I can show you one side of the issue - this works fine in PHP.  If there is a VB programmer who can fill in the other side, you've got it!

Best regards, ~Ray
<?php // RAY_mcrypt.php
// SET OUR SECRET KEY
$key     = "Secret"; // Encryption key (http://www.ciphersbyritter.com/glossary.htm#Key)



// IF ANY THING IN POST ARRAY
if (!empty($_POST))
{
// RECOVER THE THING THAT WAS POSTED
   $cryp   = base64_decode($_POST['cryp']);
   $td     = base64_decode($_POST['td']);
   $iv     = base64_decode($_POST['iv']);
   $data   = mcrypt_decrypt($td, $key, $cryp, MCRYPT_MODE_CBC, $iv);
   $data   = trim($data);
   echo "<br/>$data \n";
}




// SET OUR ENCRYPTION / DECRYPTION VARS
$td      = MCRYPT_RIJNDAEL_256; // Encryption cipher (http://www.ciphersbyritter.com/glossary.htm#Cipher)
$iv_size = mcrypt_get_iv_size($td, MCRYPT_MODE_CBC); // Dependant on cipher/mode combination (http://www.php.net/manual/en/function.mcrypt-get-iv-size.php)
$iv      = mcrypt_create_iv($iv_size, MCRYPT_RAND); // Creates an IV (http://www.ciphersbyritter.com/glossary.htm#IV)


// SET OUR TEST STRING
$data = "Shall we eat pizza or collard greens?"; // Data to encrypt (http://www.ciphersbyritter.com/glossary.htm#Encryption)
echo "<br/>Original data: $data \n";

// ENCRYPT OUR TEST STRING
$cryp = mcrypt_encrypt($td, $key, $data, MCRYPT_MODE_CBC, $iv); // Encrypts data (http://www.php.net/manual/en/function.mcrypt-encrypt.php)

// ENCODE THE FIELDS FOR TRANSFER
$b64_cryp = base64_encode($cryp);
$b64_td   = base64_encode($td);
$b64_iv   = base64_encode($iv);

?>
<form  action="<?=$_SERVER["PHP_SELF"]?>" method="post" accept-charset="UTF-8">
<input type="text" name="cryp" value="<? echo $b64_cryp; ?>" />
<input type="text" name="td"   value="<? echo $b64_td;   ?>" />
<input type="text" name="iv"   value="<? echo $b64_iv;   ?>" />
<input type="submit" />
</form>

<?

$data = mcrypt_decrypt($td, $key, $cryp, MCRYPT_MODE_CBC, $iv); // Decrypts data (http://www.php.net/manual/en/function.mcrypt-decrypt.php)
$data = trim($data);
echo "<br/>$data \n";

Open in new window

Avatar of Beverley Portlock
Use Blowfish - PHP has it built in to the mcrypt module and you can get VB implementations of it http://www11.brinkster.com/notbono/vb.asp

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One extra point when using Blowfish - you need to send the Initialisation Vector along with the encrypted data so that the decryption can be initialised into the same state as the original when the encryption took place. The initialisation vector is NOT the key so there are no security issues with storing it with the encrypted data.
Brian - good point there about sending the IV.  In the code snippet above, we need to transmit these binary strings over the internet. That is why I have base64_encode and decode in the code snippet.  It's probably baked into the examples, but if it is not, you may want to use it.
Avatar of eddysusanto
eddysusanto

ASKER

Hi guys,
Thank you. I'll try first. I'll post the result here.
Works great on my PHP and VB apss.
Thank you