AES_ENCRYPT, AES_DECRYPTå¯è½ãªæå·ãPerlã§è¡ã
ã¯ããã«
MySQLã®é¢æ°ã«AES_ENCRYPT, AES_DECRYPTã£ã¦ã®ãããã¾ãã
Rijndaelã128bitã®keylengthã§ECBã§æå·åããé¢æ°ã§ãã
AES_ENCRYPT
mysql> SELECT HEX(AES_ENCRYPT('hogehoge', 'abcdeabcdeabcdea')) AS encrypted; +----------------------------------+ | encrypted | +----------------------------------+ | 2BF77B6863989EAD599D86650A046586 | +----------------------------------+
AES_DECRYPT
mysql> SELECT AES_DECRYPT(UNHEX('2BF77B6863989EAD599D86650A046586'), 'abcdeabcdeabcdea') AS decrypted; +-----------+ | decrypted | +-----------+ | hogehoge | +-----------+
ãã®é¢æ°ã使ã£ã¦å¤ãçªã£è¾¼ãã§ããã°ã管çè
ã®ã¿ãç¥ãpassphraseãç¥ããªã人ã¯ã
復å·åºæ¥ãªãæååããã¼ã¿ãã¼ã¹ã«ããã¦ããã¾ãã
Perlã§æ±ãå ´å
- Crypt::ECB
- Crypt::Rijndael
ãå¿ è¦ã§ããåãããã«è¡ããªãã°ã
#!/usr/bin/perl use strict; use warnings; use Crypt::ECB; my $string = 'hogehoge'; my $cipher = Crypt::ECB->new(); $cipher->cipher('Rijndael'); $cipher->key('abcdeabcdeabcdea'); $cipher->padding(PADDING_AUTO); my $encrypted_hex = $cipher->encrypt_hex($string); my $decrypted = $cipher->decrypt_hex($encrypted_hex); print $encrypted_hex . "\n"; print $decrypted . "\n";
ã®ããã«è¡ãã°ãMySQLã®AES_ENCRYPT, AES_DECRYPTã¨åçã®æå·åãè¡ãäºãåºæ¥ã¾ãã
ä½è«ã§ããã©
Crypt::ECBã£ã¦Crypt::CBCã¨ãModeã表ãã¢ã¸ã¥ã¼ã«ãæ¢ã«å ¥ã£ã¦ãã¨test.plãã³ã±ãã®ã§ãauthorã«patchãéãã¾ããã
ã¨ãããããã³ã±ã¦ãç¡å®³ã§ãã念ã®ããã
*** test.pl 2000-12-17 04:21:14.000000000 +0900 --- ../test.pl.diff 2006-11-16 19:28:08.000000000 +0900 *************** *** 10,17 **** --- 10,19 ---- foreach $path (@INC) { while (<$path/Crypt/*.pm>) { + next if (/(ECB|CBC|CFB|OFB|Ctr)\.pm$/); s|^.*Crypt/||; s|\.pm$||; + print " Found $_.\n" if $crypt->cipher($_) and ++$ok; } }
test.pl.patchã§ä¿åãã¦ã
$ patch < test.pl.patch
ã§é©ç¨ããã°åé¡ãªãã§ãã