473,805 Members | 1,995 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 5174
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
2309
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
2611
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
21951
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 advanced.
33
5588
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 world")
4
16286
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
2874
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 should i put all these commands ?which directory? or will i have to write a new shell alltogether??
23
3974
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
5311
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 steps manually.
1
1281
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 some sort of "tab" or "tree" structure to the left that
0
9716
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10359
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10104
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9182
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5541
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.