mcrypt 暗号化について
調べ中
/* データ */ $key = 'asdj;asdiojsadfasdfa;sdidfasndfain'; $plain_text = "DATA DATA DATA!" ; $encData = enc($plain_text, $key) ; var_dump( bin2hex( $encData ) ); var_dump( dec( $encData, $key ) ); function enc($data,$key){ /* モジュールをオープンし、IV を作成します */ $td = getMcryptModule(); $key = substr($key, 0, mcrypt_enc_get_key_size($td)); $iv_size = mcrypt_enc_get_iv_size($td); $iv = getIv($iv_size); mcrypt_generic_init($td, $key, $iv); /* データを暗号化します */ $c_t = mcrypt_generic($td, $data); /* 後始末をします */ mcrypt_generic_deinit($td); mcrypt_module_close($td); return $c_t ; } function dec($data, $key){ /* モジュールをオープンし、IV を作成します */ $td = getMcryptModule(); $key = substr($key, 0, mcrypt_enc_get_key_size($td)); $iv_size = mcrypt_enc_get_iv_size($td); $iv = getIv($iv_size); mcrypt_generic_init($td, $key, $iv); /* データを暗号化します */ $p_t = mdecrypt_generic($td, $data); /* 後始末をします */ mcrypt_generic_deinit($td); mcrypt_module_close($td); return $p_t ; } function getMcryptModule(){ //$td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_ECB, ''); $td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, ''); return $td ; } function getIv($iv_size){ return mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM); }
結果が一緒にならない
CBCだと暗号化した値が毎回違うmcrypt_create_ivを
srand('hogehoge'); return mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
とかすると、毎回同じ。
CBCで暗号化したとき、あとで、複合したいときは、暗号化したときのivを取っておかないといけない?
これだと一緒になる
/* データ */ $key = 'asdj;asdiojsadfasdfa;sdidfasndfain'; $plain_text = "DATA DATA DATA!" ; $td = getMcryptModule(); $key = substr($key, 0, mcrypt_enc_get_key_size($td)); $iv_size = mcrypt_enc_get_iv_size($td); $iv = getIv($iv_size); $encData = enc($plain_text, $key, $iv) ; var_dump( bin2hex( $encData ) ); var_dump( dec( $encData, $key, $iv ) ); function enc($data,$key, $iv){ $td = getMcryptModule(); mcrypt_generic_init($td, $key, $iv); /* データを暗号化します */ $c_t = mcrypt_generic($td, $data); /* 後始末をします */ mcrypt_generic_deinit($td); mcrypt_module_close($td); return $c_t ; } function dec($data, $key, $iv){ $td = getMcryptModule(); mcrypt_generic_init($td, $key, $iv); /* データを暗号化します */ $p_t = mdecrypt_generic($td, $data); /* 後始末をします */ mcrypt_generic_deinit($td); mcrypt_module_close($td); return $p_t ; } function getMcryptModule(){ //$td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_ECB, ''); $td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, ''); return $td ; } function getIv($iv_size){ return mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM); }
macportsでインストールしたポスグレについて
2009-08-23 - くりまるwebつくる
入れただけで、使ってなかったんですが。initdbでいきなりつまづいた
crimaru-macbook:local coek$ sudo /opt/local/pgsql/bin/initdb -D /opt/local/var/db/postgres84/db --encoding=utf-8 --no-locale initdb: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process. crimaru-macbook:local coek$ sudo
sudo su postgres -c ' が必須っぽい
coek-macbook:local coek$ sudo su postgres -c '/opt/local/pgsql/bin/initdb -D /opt/local/var/db/postgres84/db --encoding=utf-8 --no-locale' The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale C. The default text search configuration will be set to "english". fixing permissions on existing directory /opt/local/var/db/postgres84/db ... ok creating subdirectories ... ok 以下略
起動した
crimaru-macbook:local coek$ sudo su postgres -c '/opt/local/pgsql/bin/psql -l' List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges -----------+----------+----------+-----------+-------+----------------------- postgres | postgres | UTF8 | C | C | template0 | postgres | UTF8 | C | C | =c/postgres : postgres=CTc/postgres template1 | postgres | UTF8 | C | C | =c/postgres : postgres=CTc/postgres (3 rows)
勢いで8.4を入れてみたけど、なんかすげーかわった。。。
ことえり 変換ショートカット
・ control + J --- ひらがなに変換
・ control + K --- カタカナに変換
・ control + L --- 全角英字に変換
・ control + ; (セミコロン) --- 半角カタカナに変換
・ control + : (コロン) --- 英字に変換
private protected
//親クラス class ParentClass { private $privateVar = "parent private"; protected $protectedVar = "parent Protected"; public $publicVar = "parent public" ; protected function protectedFunc2(){ return $this->privateVar ; } protected function protectedFunc3(){ return $this->protectedVar ; } } //子クラス class ChildClass extends ParentClass { //private $privateVar = "parent private"; private $privateVar = "child private"; protected $protectedVar = "child protected"; public function childPublicFunc4(){ return $this->protectedFunc2(); } public function childPublicFunc5(){ return $this->protectedFunc3(); } public function childPublicFunc6(){ return $this->privateVar; } } $c = new ChildClass(); var_dump($c->childPublicFunc4()); var_dump($c->childPublicFunc5()); var_dump($c->childPublicFunc6());
#!/usr/local/bin/php string(14) "parent private" string(15) "child protected" string(13) "child private"
issetとis_null
メモ
$ar = array(); $ar['aaa'] = "wawawa" ; $ar['bbb'] = null ; $ar['ccc'] = "" ; $ar['ddd'] = 0 ; foreach($ar as $a ){ var_dump($a); var_dump(isset($a)); var_dump(is_null($a)); var_dump("----"); } var_dump($ar['eee']); var_dump(isset($ar['eee'])); var_dump(is_null($ar['eee'])); var_dump("----");
#!/usr/local/bin/php string(6) "wawawa" bool(true) bool(false) string(4) "----" NULL bool(false) bool(true) string(4) "----" string(0) "" bool(true) bool(false) string(4) "----" int(0) bool(true) bool(false) string(4) "----" Notice: Undefined index: eee in /xxxxxxx/test.php on line 17 Call Stack: 0.0004 53000 1. {main}() /xxxxxxx/test.php:0 NULL bool(false) Notice: Undefined index: eee in /xxxxxxx/test.php on line 19 Call Stack: 0.0004 53000 1. {main}() /xxxxxxx/test.php:0 bool(true)
Zend_Fileでnewできない
$upload = new Zend_File_Transfer();
でかならずImplementation in progressといわれる
Zend_File_Transferのソース見ると
public function __construct($protocol = null) { require_once 'Zend/File/Transfer/Exception.php'; throw new Zend_File_Transfer_Exception('Implementation in progress'); #以下略
になってるけど、これだと必ずexceptionがthrowされてあたりまえな気がするけど。。。なんで?