반응형

암호화(Encryption)
- 평문을 암호화 알고리즘을 이용하여 암호문으로 변환
- 전달하는 정보를 외부로부터 보호하기위해 사용
복호화(Decryption)
- 암호문을 평문으로 변환
openssl_encrypt() / openssl_decrypt()
- php 5.3 이상에서 사용가능한 암호화/복호화 함수
- https://www.php.net/manual/en/function.openssl-encrypt.php
PHP: openssl_encrypt - Manual
I saw that a doc bug(#80236) were there mentioned that $tag usage. Here is an examples, Hopes those may help someone. 16 || ($tagLength < 12 && $tagLength !== 8 && $tagLength !== 4)) { throw new RuntimeException('The inputs `$ciphertext` incompl
www.php.net
AES-256-CBC
- 암호화에 사용되는 알고리즘의 종류
AES(Advanced Encryption Standard)
- 고급 암호화 표준
- 대칭형 블럭화 알고리즘
- 각 암호문 블럭의 크기는 128bit
256
- 암호화 키의 길이
- AES표준은 128bit, 192bit, 256bit 존재
- 암호문 블럭마다 Round마다 bit-rotation 연산
- AES128은 10Round, AES192는 12Round, AES256은 14Round
CBC(Cipher Block Chaining)
- 블럭 암호화 운영모드 중 하나로 암호 블록 체인방식
- 각 암호문 블럭 = 평문과 이전 암호문 블럭을 XOR 연산
- 첫 암호문 블럭 = 평문과 IV(Initial Vector, 초기화 벡터)를 XOR 연산
AES-256-CBC 암호화/복호화
// 평문 - 암호화 하려는 데이터
$text = 'plain-text';
// 암호화 알고리즘
$cipher = "AES-256-CBC";
// 암호화 키
$key = "encrypt-key";
// 옵션(비트별 분리 옵션으로 false시 문자열 반환)
$option = true;
// 암호문 블럭의 길이
$ivlen = openssl_cipher_iv_length($cipher);
// 초기화 벡터
$iv = substr($key.$key.$key, 0, $ivlen);
// 암호화
$encrypt = base64_encode(openssl_encrypt($text, $cipher, $key, $option, $iv));
// 복호화
$decrypt = openssl_decrypt(base64_decode($encrypt), $cipher, $key, $option, $iv);
반응형
'Web > PHP' 카테고리의 다른 글
PHP sort() (0) | 2023.06.27 |
---|---|
PSR-1: Basic Coding Standard (0) | 2023.04.21 |
PHP PDO() (0) | 2019.06.21 |
PHP mysqli() (0) | 2019.06.21 |