473,549 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"emulating" MySQL aes_encrypt() in PHP

mysql> select aes_encrypt('go rdan', 'abc');
+------------------------------+
| aes_encrypt('go rdan', 'abc') |
+------------------------------+
| p§Èb9??_é?0ö?LI Ý |
+------------------------------+

I would like to "emulate" that function in PHP. I know that MySQL AES algorithm
is RIJNDAEL_128 so I tried the following code
<?php
$iv_size = mcrypt_get_iv_s ize(MCRYPT_RIJN DAEL_128, MCRYPT_MODE_CBC );
$iv = mcrypt_create_i v($iv_size, MCRYPT_RAND);
echo mcrypt_ecb (MCRYPT_RIJNDAE L_128, 'abc', 'gordan', MCRYPT_MODE_CBC ,
$iv);
?>

but the encrypted string is different from the MySQL one :-(
and ideas?

thanks,
gordan
Jul 17 '05 #1
1 5120
Gordan wrote:
mysql> select aes_encrypt('go rdan', 'abc');
+------------------------------+
| aes_encrypt('go rdan', 'abc') |
+------------------------------+
| p§Èb9??_é?0ö?LI Ý |
+------------------------------+

I would like to "emulate" that function in PHP. I know that MySQL AES
algorithm is RIJNDAEL_128 so I tried the following code
<?php
$iv_size = mcrypt_get_iv_s ize(MCRYPT_RIJN DAEL_128, MCRYPT_MODE_CBC );
$iv = mcrypt_create_i v($iv_size, MCRYPT_RAND);
echo mcrypt_ecb (MCRYPT_RIJNDAE L_128, 'abc', 'gordan',
MCRYPT_MODE_CBC ,
$iv);
?>

but the encrypted string is different from the MySQL one :-(
and ideas?


My understanding is that the initialization vector is added to the payload
before encryption - so I've never quite understood why the examples show:
$iv = mcrypt_create_i v($iv_size, MCRYPT_RAND);
So it might be worth trying a null iv.

Other considerations include:
1) how is the key padded to the right length (16 chars)
2) maybe the data is the same - it's just being represented differently
(since it seems to be stored by MySQL in binary format)

HTH

C.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2279
by: Omar E Contreras | last post by:
Hi guys, Let me explain what I want to do in just 3 steps: Step 1: An HTML page that has a form which passes some data to an aspx page Step 2: The aspx page take this values and add some others, lets say VarA = "Fun" Step 3:
1
2598
by: Niall Smart | last post by:
Hi I'm trying to emulate a "following-sibling-or-self" XPath axis without using the union operator. The XML looks like this: <deeply-nested> <select> <option value="1">One</option> <option value="2" selected="selected">Two</option> <option value="3">Three</option>
388
21474
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's worth the $25USD. I'm just looking for a book on Pointers, because from what I've read it's one of the toughest topics to understand. thanks in...
33
5536
by: ankursinha | last post by:
Hi, Is it possible to write a C program that prints "Hello World" on screen without having a single semi-colon in the entire program? The extra constraint here is that u r not allowed to use if,while,switch etc. So far,i figured this could be done by insertint the printf statement in main as shown: int main(int argc=printf("Hello...
4
16247
by: dschruth | last post by:
Hello. Can anybody solve this problem? I am using a server-side language (PERL) to *try* to POST data to a HTTPS login script that doesn't have a standard "submit" button. The form appears to use javascript to submit the document via the browser's DOM. <form action='loginScript.cgi' method="post" name="loginForm">
1
2860
by: apsonline | last post by:
hi people i want to work on a project that would "emulate" unix commands like ls,rm etc... by making use of uunix system calls . by writing programs in c++ using system calls ,these programs would work exactly the same way as the unix commands would work. but will the unix shell accept these commanands(which are defined by me) ? where...
23
3932
by: steve.j.donovan | last post by:
Hi guys, We have the following macro: #define NEXT(type,p) (*((type*)(p))++) It provides a way to poke variable sized data into an array of pcode for a simple VM. e.g,
13
5280
by: MLH | last post by:
Would like to run the control panel's Internet Date & Time program from VBA - emulating opening it, clicking the Internet Time tab and the Update Now button. I don't really care for the user to see all this. Would just like to sync the system time with the facility built-in to XP and automatically w/o asking the user to go through the...
1
1271
by: samadams_2006 | last post by:
Hello, I have Visual Studio 2005 and am developing my first web site. I see TreeViews, ReportViewers, etc. but I'm not sure which approach that I should choose. Let me tell you what I'm going to do and maybe you can offer suggestions: 1) I'm going to have a bunch of articles that I'm going to be posting to this website. 2) I need...
0
7546
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7985
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7830
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6071
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
784
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.