OneSM3 PHP Library: Installation, Usage, and Performance Comparison with OpenSSL
This article introduces the OneSM3 PHP library for the SM3 cryptographic hash, provides Composer installation steps, usage examples for string and file signing, and presents performance benchmark results comparing it with OpenSSL and another PHP SM3 implementation.
OneSM3 is a PHP library implementing the SM3 cryptographic hash algorithm, with source code hosted on GitHub.
Code repository : https://github.com/lizhichao/sm
Installation : Use Composer to add the package.
composer require lizhichao/one-smUsage examples:
require __DIR__ . '/vendor/autoload.php'; // String signature echo \OneSm\Sm3::sign('abc') . PHP_EOL; echo \OneSm\Sm3::sign(str_repeat("adfas哈哈哈", 100)) . PHP_EOL; // File signature echo \OneSm\Sm3::signFile(__FILE__) . PHP_EOL;Performance testing compares the library against OpenSSL and another PHP SM3 implementation (SM3-PHP). Run the benchmark script:
php bench.phpThe benchmark results show identical hash values for OpenSSL and one-sm3, while SM3-PHP produces a different hash; execution times are approximately 4.76 ms for OpenSSL, 5.53 ms for one-sm3, and 708 ms for SM3-PHP.
For the full source and detailed results, see the original article linked below.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.