Data type: Difference between revisions
Jump to navigation
Jump to search
→雜湊碼 (hash value) e.g. MD5, SHA
m (→台灣身分證號/統一證號) |
|||
| Line 78: | Line 78: | ||
=== 雜湊碼 (hash value) e.g. MD5, SHA === | === 雜湊碼 (hash value) e.g. MD5, SHA === | ||
MD5 | |||
* [https://zh.wikipedia.org/wiki/MD5 MD5]: CHAR(32) or VARCHAR(32)<ref>[https://stackoverflow.com/questions/14922208/can-i-use-varchar32-for-md5-values php - Can I use VARCHAR(32) for md5() values? - Stack Overflow]</ref> | * [https://zh.wikipedia.org/wiki/MD5 MD5]: CHAR(32) or VARCHAR(32)<ref>[https://stackoverflow.com/questions/14922208/can-i-use-varchar32-for-md5-values php - Can I use VARCHAR(32) for md5() values? - Stack Overflow]</ref> | ||
[https://zh.wikipedia.org/wiki/SHA%E5%AE%B6%E6%97%8F SHA]<ref>[https://stackoverflow.com/questions/2240973/how-long-is-the-sha256-hash mysql - How long is the SHA256 hash? - Stack Overflow]</ref><ref>[http://fishjerky.blogspot.com/2013/06/md5sha512.html 魚乾的筆記本: MD5被破解了,要改用SHA]</ref>: | |||
* (1) HEX: CHAR(64) Using [http://php.net/manual/en/function.hash-file.php PHP: hash_file()], MySQL [https://dev.mysql.com/doc/refman/5.6/en/encryption-functions.html#function_sha2 SHA2(str, hash_length)] | |||
* (2) Binary: BINARY(32) In PHP using [http://php.net/manual/en/function.hex2bin.php hex2bin()] e.g. {{kbd | key=<nowiki>echo hex2bin(hash_file('sha256', $file_path));</nowiki>}}, In MySQL using [https://www.w3resource.com/mysql/string-functions/mysql-unhex-function.php UNHEX() function] e.g. {{kbd | key=<nowiki>SELECT UNHEX(SHA2('The quick brown fox jumped over the lazy dog.', 256))</nowiki>}} | |||
* (3) CHAR(60) if using the MySQL [https://www.w3resource.com/mysql/encryption-and-compression-functions/sha1().php SHA1() function] | |||
==== Retrieve the hash value from string or file content ==== | ==== Retrieve the hash value from string or file content ==== | ||