php 암호화
페이지 정보
본문
//PHP 5.3.0 부터 openssl_encrypt 사용가능
//상수정의
//키
define('KEY', '01234567890123456789012345678901');
//128bit (16자리)
define('KEY_128', substr(KEY, 0, 128 / 8));
//256bit (32자리)
define('KEY_256', substr(KEY, 0, 256 / 8));
$str1 = '안녕하세요 이것은 무엇일까요?';
echo 'plain : ' . $str1 . '<br>';
$str2 = openssl_encrypt($str1, 'AES-128-CBC', KEY_128, 0, KEY_128);
echo 'AES128 encrypted : ' . $str2 . '<br>';
$str3 = openssl_decrypt($str2, 'AES-128-CBC', KEY_128, 0, KEY_128);
echo 'AES128 decrypted : ' . $str3 . '<br>';
$str4 = openssl_encrypt($str1, 'AES-256-CBC', KEY_256, 0, KEY_128);
echo 'AES256 encrypted : ' . $str4 . '<br>';
$str5 = openssl_decrypt($str4, 'AES-256-CBC', KEY_256, 0, KEY_128);
echo 'AES256 decrypted : ' . $str5 . '<br>';
$str6 = base64_encode(hash('SHA256', $str1, true));
echo 'SHA256 encrypted : ' . $str6 . '<br>';
//상수정의
//키
define('KEY', '01234567890123456789012345678901');
//128bit (16자리)
define('KEY_128', substr(KEY, 0, 128 / 8));
//256bit (32자리)
define('KEY_256', substr(KEY, 0, 256 / 8));
$str1 = '안녕하세요 이것은 무엇일까요?';
echo 'plain : ' . $str1 . '<br>';
$str2 = openssl_encrypt($str1, 'AES-128-CBC', KEY_128, 0, KEY_128);
echo 'AES128 encrypted : ' . $str2 . '<br>';
$str3 = openssl_decrypt($str2, 'AES-128-CBC', KEY_128, 0, KEY_128);
echo 'AES128 decrypted : ' . $str3 . '<br>';
$str4 = openssl_encrypt($str1, 'AES-256-CBC', KEY_256, 0, KEY_128);
echo 'AES256 encrypted : ' . $str4 . '<br>';
$str5 = openssl_decrypt($str4, 'AES-256-CBC', KEY_256, 0, KEY_128);
echo 'AES256 decrypted : ' . $str5 . '<br>';
$str6 = base64_encode(hash('SHA256', $str1, true));
echo 'SHA256 encrypted : ' . $str6 . '<br>';
관련링크
- 이전글mysql 중복컬럼 지우기 20.02.21
- 다음글apache 최신 버전(2.4.41) 설치 yum 이용 20.02.21
댓글목록
등록된 댓글이 없습니다.