Server/DB

MySQL) AES 128 <-> 256

Juzdalua 2023. 1. 30. 14:33

현재 적용중인 모드를 확인한다.

디폴트는 aes-128-ecb이다.

SELECT @@session.block_encryption_mode;

 

아래 명령어로 모드를 변경할 수 있다.

SET block_encryption_mode = 'aes-128-ecb';
SET block_encryption_mode = 'aes-256-ecb';

 

변경 후 실행결과를 살펴보자.

SELECT
AES_ENCRYPT('hi', SHA2(CONCAT('key1','key2'), 256)),
TO_BASE64(AES_ENCRYPT('hi', SHA2(CONCAT('key1','key2'), 256)))
;

 

참고)

https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_aes-encrypt

 

MySQL :: MySQL 5.7 Reference Manual :: 12.14 Encryption and Compression Functions

12.14 Encryption and Compression Functions Many encryption and compression functions return strings for which the result might contain arbitrary byte values. If you want to store these results, use a column with a VARBINARY or BLOB binary string data type

dev.mysql.com