# Encrypt PHP, Decrypt Xojo

**URL:** <https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983>\
**Category:** General\
**Created:** [July 16, 2014, 3:12am UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983 "2014-07-16T03:12:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Gorbutt](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_gorbutt/32/261_2.png) [@Richard\_Gorbutt](https://forum.xojo.com/u/Richard_Gorbutt)\
**Post date:** [July 16, 2014, 3:12am UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/1 "2014-07-16T03:12:45Z")

</div>

Hi all,

I have a need to encrypt some data in PHP and store in a MYSQL database, and then decrypt that with a XOJO Console app triggered by CRON. I have the MBS plugins, and was playing with Blowfish (MBS) and mcrypt in PHP but never the twain they shall meet.

Anyone done similar?

Thanks

---

<div class="post-metadata">

**Author:** ![Johnny\_Harris](https://forum.xojo.com/user_avatar/forum.xojo.com/johnny_harris/32/1987_2.png) [@Johnny\_Harris](https://forum.xojo.com/u/Johnny_Harris)\
**Post date:** [July 16, 2014, 3:41am UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/2 "2014-07-16T03:41:12Z")

</div>

I did a small project with PHP, Xojo, Einhugur Plugins and MySQL a few years ago. I just needed some simple encryption to store personal information. I don’t recall any of the code. If nobody else has a good example by tomorrow, I’ll try to find the code that I used for the encryption. I do recall it took a little time and research to get it working.

---

<div class="post-metadata">

**Author:** ![Richard\_Vivash](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@Richard\_Vivash](https://forum.xojo.com/u/Richard_Vivash)\
**Post date:** [July 16, 2014, 10:43am UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/3 "2014-07-16T10:43:53Z")

</div>

I can’t help unfortunately, but I have also tried to use the public/private key encryption available in Xojo and interface with OpenSSL public/private key encryption available through PHP. Couldn’t get that to work either. The Keys produced by Xojo were said to be badly formed by PHP and the same visa versa.

So I’d also be interested in a solution to encrypt data between PHP and Xojo.

---

<div class="post-metadata">

**Author:** ![Johnny\_Harris](https://forum.xojo.com/user_avatar/forum.xojo.com/johnny_harris/32/1987_2.png) [@Johnny\_Harris](https://forum.xojo.com/u/Johnny_Harris)\
**Post date:** [July 16, 2014, 11:07am UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/4 "2014-07-16T11:07:42Z")

</div>

I was able to access the PHP files from home and apparently I used a 3rd party library: [http://phpseclib.sourceforge.net/](http://phpseclib.sourceforge.net/)

When I get to work I’ll look for the Xojo project.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [July 16, 2014, 11:11am UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/5 "2014-07-16T11:11:15Z")

</div>

I did this years ago using AES\_CBC in einhugur’s plugins, but darned if I remember where that code is…

---

<div class="post-metadata">

**Author:** ![Richard\_Gorbutt](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_gorbutt/32/261_2.png) [@Richard\_Gorbutt](https://forum.xojo.com/u/Richard_Gorbutt)\
**Post date:** [July 16, 2014, 1:11pm UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/6 "2014-07-16T13:11:41Z")

</div>

Thanks all, I appreciate the response. For some reason PHP.Blowfish.EncryptECB \<\> Xojo.BlowFishMBS.EncryptECB (simplified) using same key and string and encoding. ☹

I’ll investigate the phpseclib stuff.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [July 16, 2014, 1:26pm UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/7 "2014-07-16T13:26:02Z")

</div>

[quote=112047:@Richard Gorbutt]Thanks all, I appreciate the response. For some reason PHP.Blowfish.EncryptECB \<\> Xojo.BlowFishMBS.EncryptECB (simplified) using same key and string and encoding. ☹

I’ll investigate the phpseclib stuff.[/quote]  
Make sure the Endianess is set the same. If they’re not you’ll have troubles.

---

<div class="post-metadata">

**Author:** ![Johnny\_Harris](https://forum.xojo.com/user_avatar/forum.xojo.com/johnny_harris/32/1987_2.png) [@Johnny\_Harris](https://forum.xojo.com/u/Johnny_Harris)\
**Post date:** [July 16, 2014, 8:11pm UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/8 "2014-07-16T20:11:09Z")

</div>

I looked up the code I used several years ago and it was using the Einhugur plugins and AES\_CBC.

This code seems to work with the MBS Plugins. Be sure to look at the example provided in the MBS downloads example folder.

```auto
<?php
function hex2str( $hex ) {
  return pack('H*', $hex);
}

function str2hex( $str ) {
  return array_shift( unpack('H*', $str) );
}

$key = "ABCD123";
$secret = "Xojo Is Fun ";
// Encrypt Secret
$crypted = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $secret, MCRYPT_MODE_CBC);

$td = mcrypt_module_open('blowfish', '', 'cbc', '');
$ivsize = mcrypt_enc_get_iv_size($td);
$iv = hex2str("0000000000000000");
// Decrypt Secret
mcrypt_generic_init($td,$key, $iv);
$plaintext = mdecrypt_generic($td, $crypted);

print 'The Secret: ' . $secret . '<br><br>';
print 'Encrypted As HEX: ' . strtoupper(bin2hex($crypted)) . '<br><br>';
print "Decrypted Secret: " . $plaintext;
?>
```

---

<div class="post-metadata">

**Author:** ![Richard\_Gorbutt](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_gorbutt/32/261_2.png) [@Richard\_Gorbutt](https://forum.xojo.com/u/Richard_Gorbutt)\
**Post date:** [July 16, 2014, 9:55pm UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/9 "2014-07-16T21:55:37Z")

</div>

Many thanks, I’ll give it a try hopefully over the weekend.

---

<div class="post-metadata">

**Author:** ![Richard\_Gorbutt](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_gorbutt/32/261_2.png) [@Richard\_Gorbutt](https://forum.xojo.com/u/Richard_Gorbutt)\
**Post date:** [July 19, 2014, 3:27am UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/10 "2014-07-19T03:27:01Z")

</div>

Perfect, did the trick. MBS Blowfish and the guidance above. Many thanks.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:19pm UTC](https://forum.xojo.com/t/encrypt-php-decrypt-xojo/17983/11 "2020-10-29T17:19:59Z")

</div>


