PHP项目中libsodium封装 Halite

码农软件 · 软件分类 · 加密/解密软件包 · 2019-09-30 15:44:26

软件介绍

Halite 是PHP项目中一个简单的libsodium封装包。Halite提供高级的加密接口,依靠其所有潜在的密码操作libsodium。

Halite 基本 API:

示例1:加密解密消息

首先,生成一个key

<?php
use ParagonIE\Halite\KeyFactory;

$encKey = KeyFactory::generateEncryptionKey();
KeyFactory::save($encKey, '/path/outside/webroot/encryption.key');

然后,加密解密消息

<?php
use ParagonIE\Halite\HiddenString;
use ParagonIE\Halite\KeyFactory;
use ParagonIE\Halite\Symmetric\Crypto as Symmetric;

$encryptionKey = KeyFactory::loadEncryptionKey('/path/outside/webroot/encryption.key');

$message = new HiddenString('This is a confidential message for your eyes only.');
$ciphertext = Symmetric::encrypt($message, $encryptionKey);

$decrypted = Symmetric::decrypt($ciphertext, $encryptionKey);

var_dump($decrypted === $message); // bool(true)

示例2:用password-derived key 加密消息

<?php
use ParagonIE\Halite\HiddenString;
use ParagonIE\Halite\KeyFactory;
use ParagonIE\Halite\Symmetric\Crypto as Symmetric;

$passwd = new HiddenString('correct horse battery staple');
// Use random_bytes(16); to generate the salt:
$salt = "\xdd\x7b\x1e\x38\x75\x9f\x72\x86\x0a\xe9\xc8\x58\xf6\x16\x0d\x3b";

$encryptionKey = KeyFactory::deriveEncryptionKey($passwd, $salt);

$message = new HiddenString('This is a confidential message for your eyes only.');
$ciphertext = Symmetric::encrypt($message, $encryptionKey);
echo $ciphertext, "\n";

本文地址:https://codercto.com/soft/d/15739.html

学习Web设计

学习Web设计

罗宾斯 / 靳志伟 / 机械工业出版社 / 2009-1 / 65.00元

《学习Web设计(第3版)》从说明网站和网页是如何工作开始,逐步深入。当你看完《学习Web设计(第3版)》时,你将掌握使用优化的图像文件来创建多列CSS布局的技术,而且你将知道如何创建网页。这一版经过了彻底的修订,它可以教你如何根据现代设计的实践经验和专业标准来创建网站。《学习Web设计(第3版)》包含了一些练习,可以帮助你学习各种技术,还有一些小测验可以确保你及时掌握重要的概念。如果你对网站设计......一起来看看 《学习Web设计》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码