ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` wget https://github.com/GmSSL/GmSSL-PHP/archive/refs/tags/v1.1.0.zip unzip v1.1.0.zip ``` ``` cd GmSSL-PHP-1.1.0/ /usr/local/php-7.4/bin/phpize sudo ./configure --with-php-config=/usr/local/php-7.4/bin/php-config ``` 编译 ``` ---------------------------------------------------------------------- Libraries have been installed in: /home/www/build/GmSSL-PHP-1.1.0/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don't forget to run 'make test'. ``` 安装 ``` sudo make install Installing shared extensions: /usr/local/php-7.4/lib/php/extensions/no-debug-non-zts-20190902/ ``` GmSSL PHP扩展需要在`php.ini`中启用。 ``` sudo vim `php-config --ini-path`/php.ini ``` 末尾添加一个新行`extension=gmssl` 打印常量值`GMSSL_PHP_VERSION`以查看是否正确安装了GmSSL扩展 ``` <?php print(GMSSL_PHP_VERSION."\n"); ``` 执行打印 ``` php gmssl.php 1.0.0 ``` ### SM3示例 SM3是具有256位输出散列值的加密散列函数。计算字符串`Tinywan 开源技术小栈`的SM3摘要。 `sm3.php` 文件 ``` <?php /** * @desc sm3.php * @author Tinywan(ShaoBo Wan) * @date 2024/7/2 */ declare(strict_types=1); $hash = gmssl_sm3('Tinywan 开源技术小栈'); print(bin2hex($hash)."\n"); ``` 执行打印 ``` php sm3.php bda240dbc6dc36670ff3702ac2e336aea6fc4353b7746dd4a1ffbc74fa3d5529 ```