Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 818
  • Last Modified:

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.
0
eddysusanto
Asked:
eddysusanto
  • 3
  • 2
  • 2
1 Solution
 
Ray PaseurCommented:
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

0
 
Beverley PortlockCommented:
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

0
 
Ray PaseurCommented:
Check the links below the green code block here:
http://www.chilkatsoft.com/p/php_blowfish.asp

I have not tested them together, but the page claims that they should work.
http://www.example-code.com/vb/crypt2_blowfish_matchPhp.asp

Best of luck with your project, ~Ray
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Beverley PortlockCommented:
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.
0
 
Ray PaseurCommented:
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.
0
 
eddysusantoAuthor Commented:
Hi guys,
Thank you. I'll try first. I'll post the result here.
0
 
eddysusantoAuthor Commented:
Works great on my PHP and VB apss.
Thank you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now