Created
August 24, 2022 09:26
-
-
Save Eminlin/3dc6d4534b6dba9a253702ae38f7a25d to your computer and use it in GitHub Desktop.
PHP Des加解密文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$originFile = file_get_contents('./20211026111907.png'); //等待加密文件 | |
$key = substr(openssl_digest(openssl_digest('password', 'sha1', true), 'sha1', true), 0, 16);// password 为密钥 | |
$enData = openssl_encrypt($originFile, 'DES-ECB', $key, OPENSSL_RAW_DATA); //需要 openssl 支持 | |
$deData = openssl_decrypt($enData, 'DES-ECB', $key, OPENSSL_RAW_DATA); | |
// echo bin2hex($data)."\n"; //输出二进制转十六进制 | |
// echo base64_encode($data); //输出加密后的 base64 字符串 | |
file_put_contents("./en.png", $enData); //输出加密文件 | |
file_put_contents("./de.png", $deData); //输出解密文件 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment