语法种子/libsodium

PHP的Libsodium扩展函数的包装/外观类。涵盖了对称加密和公钥加密函数。

v1.0.3 2022-03-13 16:20 UTC

This package is auto-updated.

Last update: 2024-09-13 21:44:49 UTC


README

GitHub tag (latest SemVer)   PHP v8.0+   PHP v8.1+   License: MIT
follow on Twitter  Sponsor Project

PHP的LibSodium扩展的包装/外观类。提供对称加密和解密静态方法,以及密钥生成方法。

十六进制编码:所有输出转换为十六进制。输入期望十六进制编码值。

安装

通过Composer

composer require syntaxseed/libsodium

或添加到composer.json

"require": {
    "syntaxseed/libsodium": "^1.0"
},

静态函数

  • 对称加密(一个密钥)

    • generateSymmetricKey()
    • symmetricEncrypt($secretString, $symmetricKey)
    • symmetricDecrypt($encryptedString, $nonce, $key)
  • 公钥加密(公钥/私钥对)

    • generateKeyPair()
    • publicKeyEncrypt($secretString, $theirPublicKey, $ourPrivateKey)
    • publicKeyDecrypt($encryptedString, $nonce, $ourPublicKey, $theirPrivateKey)

用法

查看examples/目录。

变更日志

  • v1.0.0 - (2018-10-27) 创建。添加到GitHub。
    • v1.0.1 - (2018-10-27) 更新README,添加Composer说明。
    • v1.0.2 - (2022-02-02) 测试PHP 8.0。添加示例用法文件。
    • v1.0.3 - (2022-03-13) 测试PHP 8.1。修复PSR格式。