md5を使う
すみません。。。思いっきり勘違いしてました。以下が正しい内容です。
- md5は8.3.1でも標準関数として使えます
- pgcryptoを使うと、digest関数、hmac関数などが使えるようになる
- make install後、関数を有効にしたいデータベースに対して、PostgreSQLのスーパーユーザーでcontribディレクトリにあるpgcrypto.sqlを実行する必要がある
- PostgreSQLの再起動は不要
# cd /usr/local/src/postgresql-8.3.1/contrib/pgcrypto/ # make # make install # su - postgres $ psql -d databasename -f /path/top/contrib/pgcrypto/pgcrypto.sql $ psql -U dbuser databasename databasename=> select encode(digest('test_string', 'md5'), 'hex'); encode ---------------------------------- 3474851a3410906697ec77337df7aae4 (1 row) databasename=> select encode(digest('test_string', 'sha1'), 'hex'); encode ------------------------------------------ c58efadcf9f6b303e44e4a62dd984bbc8cae6e99 (1 row) databasename=>id:iakioさん、指摘ありがとうございました。
個人用メモ。
PostgreSQL(8.3.1)で「組み込み関数としての」md5を使いたかったのだが、contribとして提供されているらしい。
このpgcryptoをインストールすると各種ハッシュ関数が使えるようになる。
# cd /usr/local/src/postgresql-8.3.1/contrib/pgcrypto/ # make # make install # /etc/rc.d/init.d/postgresql stop # /etc/rc.d/init.d/postgresql start #
とりあえず、動作確認。
$ psql databasename Welcome to psql 8.3.1, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit databasename=> select md5('test_string'); md5 ---------------------------------- 3474851a3410906697ec77337df7aae4 (1 row) databasename=> \q $ php -r 'echo md5("test_string") . PHP_EOL;' 3474851a3410906697ec77337df7aae4 $
追記(2008/10/10 10:30)
すみません。かなり嘘っぱちでした>< 追記した方を参照してください。