header image

Ryuzeeの他サイト

mixi Twitter Twitter

Categories

携帯対応

QRコード

RING

人気ブログランキング



新着記事

PHPで可逆暗号化する方法

cryptやmd5は、不可逆暗号化であるので、Crypt_Blowfishを利用して可逆暗号化をする。

導入方法はお決まりの通り。

[root@sakae staff]# /usr/bin/pear install Crypt_Blowfish
install ok: channel://pear.php.net/Crypt_Blowfish-1.1.0RC1

サンプルソース

<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=euc-jp'>
<title>blowfish sample</title>
</meta></head>
<body>

<?php
$lib = '/usr/share/pear';
set_include_path($lib . PATH_SEPARATOR . get_include_path());

require_once('Crypt/Blowfish.php');

$secret_key = 'hogehoge';

$blowfish = new Crypt_Blowfish($secret_key);

#$text = 'この文字を暗号化します';
$text = 'http://www.example.com';
echo('---暗号化前---<br>');
echo($text);
echo('<br /><br />');

echo('---暗号化後---<br />');
$crypt_text = $blowfish->encrypt($text);
echo($crypt_text);
echo('<br /><br />');

echo('---復号後---<br />');
echo($blowfish->decrypt($crypt_text));
echo('<br /><br />');

?>

</body>
</html>

考えられる利用方法

* なんかURLに暗号化したキーをつけるとか(但しBASE64でエンコード必須)
* DBに個人情報を登録する時とかに一応暗号化してみる、とか

Ratings

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

“可逆暗号化する”へのコメントはありません。

コメントはありません。是非コメントしてください。

コメントする

XHTML: 以下のタグが利用可能です: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback

 

add to hatena hatena.comment (0) add to del.icio.us (0) add to livedoor.clip (0) add to Yahoo!Bookmark (0) Total: 0