mysqlAES
[ class tree: mysqlAES ] [ index: mysqlAES ] [ all elements ]

Class: mysqlAES

Source Location: /mysqlAES/mysqlAES.php

Class Overview


mysqlAES 패키지는 MySQL의 AES_EMCRYPT, AES_DECRYPT, HEX, UNHEX 함수를 php에서 호환되게 사용할 수 있도록 하는 기능을 제공한다.


Constants

Methods



Class Details

[line 59]
mysqlAES 패키지는 MySQL의 AES_EMCRYPT, AES_DECRYPT, HEX, UNHEX 함수를 php에서 호환되게 사용할 수 있도록 하는 기능을 제공한다.

encrypt method와 decrypt method의 경우, key 길이가 128bit(16byte)이면 MySQL과 MariaDB의 AES_ENCRYPT/AES_DECRYPT 함수와 완벽하게 호환이 된다.

key 길이가 192또는 256bit일 경우에는 oops에서 제공하는 lib_mysqludf_aes256 UDF에서 제공하는 AES256_ENCRYPT, AES256_DECRYPT와 완변하게 호환이 된다.

예제:

  1. <?php
  2. require_once 'mysqlAES.php';
  3.  
  4. use oops\Encrypt\mysqlAES as myAES;
  5.  
  6. $cipher '123123 궁중 떡뽁이';
  7. $keys array (
  8.     '128' => '0123456789012345',
  9.     '192' => '012345678901234567890123',
  10.     '256' => '01234567890123456789012345678901'
  11. );
  12.  
  13. try {
  14.     printf ('Original Data     : %s' PHP_EOL$cipher);
  15.     printf ("Expected Data     :\n");
  16.     printf ("           128bit : E788F1C5FB172B546DA83BAE78D2E07863263129FA8539C443B35512CF8447E4\n");
  17.     printf ("           192bit : 08DBCABD2875EAC628630EF2033CABBE72C8E13D7197B9EE8F6845336A9C0806\n");
  18.     printf ("           256bit : DAE591EE85369CBFF489FBB2E791934ACD14329CC94D756D3A26B119AC7C9DC5\n");
  19.  
  20.     foreach $keys as $key => $enckey{
  21.         echo "------------------------------------------------------------------------------------\n";
  22.         $enc myAES::hex (myAES::encrypt ($cipher$enckey));
  23.         printf ('%d bit encryption: %s' PHP_EOL$key$enc);
  24.         printf ('%d bit key length: %d' PHP_EOL$keystrlen ($enckey));
  25.         printf ('%d bit hex length: %d' PHP_EOL$keystrlen ($enc));
  26.         $dec myAES::decrypt (myAES::unhex ($enc)$enckey);
  27.         printf ('%d bit revoke    : %s' PHP_EOL$key$dec);
  28.     }
  29. catch Exception $e {
  30.     fprintf (STDERR"%s\n"$e->getMessage ());
  31.     print_r ($e->getTrace ()) "\n";
  32. }
  33.  
  34. ?>




[ Top ]


Class Methods


static method decrypt [line 212]

static string decrypt( string ?$cipher, string ?$key)

Decrypt using AES

This method is compatible AES_DECRYPT function of mysql, if key is 128 bit And then, If key is 192 or 256 bit, this method is compatible follow APIS:

Example:
  1. <?php
  2. require_once 'mysqlAES.php';
  3.  
  4. use oops\Encrypt\mysqlAES as myAES;
  5.  
  6. $cipher '123123 궁중 떡뽁이';
  7. $keys array (
  8.     '128' => '0123456789012345',
  9.     '192' => '012345678901234567890123',
  10.     '256' => '01234567890123456789012345678901'
  11. );
  12.  
  13. try {
  14.     printf ('Original Data     : %s' PHP_EOL$cipher);
  15.     printf ("Expected Data     :\n");
  16.     printf ("           128bit : E788F1C5FB172B546DA83BAE78D2E07863263129FA8539C443B35512CF8447E4\n");
  17.     printf ("           192bit : 08DBCABD2875EAC628630EF2033CABBE72C8E13D7197B9EE8F6845336A9C0806\n");
  18.     printf ("           256bit : DAE591EE85369CBFF489FBB2E791934ACD14329CC94D756D3A26B119AC7C9DC5\n");
  19.  
  20.     foreach $keys as $key => $enckey{
  21.         echo "------------------------------------------------------------------------------------\n";
  22.         $enc myAES::hex (myAES::encrypt ($cipher$enckey));
  23.         printf ('%d bit encryption: %s' PHP_EOL$key$enc);
  24.         printf ('%d bit key length: %d' PHP_EOL$keystrlen ($enckey));
  25.         printf ('%d bit hex length: %d' PHP_EOL$keystrlen ($enc));
  26.         $dec myAES::decrypt (myAES::unhex ($enc)$enckey);
  27.         printf ('%d bit revoke    : %s' PHP_EOL$key$dec);
  28.     }
  29. catch Exception $e {
  30.     fprintf (STDERR"%s\n"$e->getMessage ());
  31.     print_r ($e->getTrace ()) "\n";
  32. }
  33.  
  34. ?>




Tags:

return:  decrypted data by AES. If $cipyer or $key has empty value, return null.
access:  public


Parameters:

string   ?$cipher   cipher data for being decryption
string   ?$key   decryption key
  • 128bit : 16 byte string
  • 192bit : 24 byte string
  • 256bit : 32 byte string

[ Top ]

static method encrypt [line 160]

static string encrypt( string ?$cipher, string ?$key)

Encrypt using AES

This method is compatible AES_ENCRYPT function of mysql, if key is 128 bit. And then, If key is 192 or 256 bit, this method is compatible follow APIS:

Example:
  1. <?php
  2. require_once 'mysqlAES.php';
  3.  
  4. use oops\Encrypt\mysqlAES as myAES;
  5.  
  6. $cipher '123123 궁중 떡뽁이';
  7. $keys array (
  8.     '128' => '0123456789012345',
  9.     '192' => '012345678901234567890123',
  10.     '256' => '01234567890123456789012345678901'
  11. );
  12.  
  13. try {
  14.     printf ('Original Data     : %s' PHP_EOL$cipher);
  15.     printf ("Expected Data     :\n");
  16.     printf ("           128bit : E788F1C5FB172B546DA83BAE78D2E07863263129FA8539C443B35512CF8447E4\n");
  17.     printf ("           192bit : 08DBCABD2875EAC628630EF2033CABBE72C8E13D7197B9EE8F6845336A9C0806\n");
  18.     printf ("           256bit : DAE591EE85369CBFF489FBB2E791934ACD14329CC94D756D3A26B119AC7C9DC5\n");
  19.  
  20.     foreach $keys as $key => $enckey{
  21.         echo "------------------------------------------------------------------------------------\n";
  22.         $enc myAES::hex (myAES::encrypt ($cipher$enckey));
  23.         printf ('%d bit encryption: %s' PHP_EOL$key$enc);
  24.         printf ('%d bit key length: %d' PHP_EOL$keystrlen ($enckey));
  25.         printf ('%d bit hex length: %d' PHP_EOL$keystrlen ($enc));
  26.         $dec myAES::decrypt (myAES::unhex ($enc)$enckey);
  27.         printf ('%d bit revoke    : %s' PHP_EOL$key$dec);
  28.     }
  29. catch Exception $e {
  30.     fprintf (STDERR"%s\n"$e->getMessage ());
  31.     print_r ($e->getTrace ()) "\n";
  32. }
  33.  
  34. ?>




Tags:

return:  encrypted data by AES. If $cipyer or $key has empty value, return null
access:  public


Parameters:

string   ?$cipher   The plaintext message data to be encrypted.
string   ?$key   encryption key
  • 128bit : 16 byte string
  • 192bit : 24 byte string
  • 256bit : 32 byte string

[ Top ]

static method hex [line 89]

static string hex( string ?$v)

Return a hexadecimal representation of a decimal or string value

This method is compatible HEX function of mysql

Example:

  1.         $enc myAES::hex (myAES::encrypt ($cipher$enckey));




Tags:

return:  hexadecimal data. If given parameter $v is empty, return null.
access:  public


Parameters:

string   ?$v   original data

[ Top ]

static method unhex [line 111]

static string unhex( string ?$v)

Return a string containing hex representation of a number

This method is compatible UNHEX function of mysql

Example:

  1.         $dec myAES::decrypt (myAES::unhex ($enc)$enckey);




Tags:

return:  Returns an ASCII string containing the hexadecimal representation. If given parameter $v is empty, return null.
access:  public


Parameters:

string   ?$v   hexadecimal data

[ Top ]

constructor __construct [line 73]

mysqlAES __construct( )

oops\Encrypt\mysqlAES 초기화



Tags:

access:  public


[ Top ]


Class Constants

AES_BLOCK_SIZE =  16

[line 64]

AES block 사이즈


[ Top ]



Documentation generated on Tue, 14 May 2019 02:00:39 +0900 by phpDocumentor 1.4.4