首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

openssl_seal

(PHP 4 >= 4.0.4, PHP 5, PHP 7)

openssl_seal — Seal (encrypt) data

描述

代码语言:javascript
复制
int openssl_seal ( string $data , string &$sealed_data , array &$env_keys , array $pub_key_ids [, string $method = "RC4" [, string &$iv ]] )

openssl_seal()data通过使用给定method的随机生成的密钥来加密(加密)。密钥用与每个与标识符相关联的公钥加密,pub_key_ids并且每个加密密钥都被返回env_keys。这意味着可以将密封数据发送给多个收件人(前提是您已获得公钥)。每个收件人都必须同时收到密封数据和使用收件人公钥加密的信封密钥。

参数

data

要密封的数据。

sealed_data

密封的数据。

env_keys

一组加密密钥。

pub_key_ids

公钥资源标识符数组。

method

密码方法。

iv

初始化向量。

返回值

返回成功或FALSE错误时密封数据的长度。如果密封的数据成功返回sealed_data,并且信封键入env_keys

Changelog

Version

Description

7.0.0

The iv has been added.

5.3.0

The method has been added.

示例

Example #1 openssl_seal() example

代码语言:javascript
复制
<?php
// $data is assumed to contain the data to be sealed

// fetch public keys for our recipients, and ready them
$fp = fopen("/src/openssl-0.9.6/demos/maurice/cert.pem", "r");
$cert = fread($fp, 8192);
fclose($fp);
$pk1 = openssl_get_publickey($cert);
// Repeat for second recipient
$fp = fopen("/src/openssl-0.9.6/demos/sign/cert.pem", "r");
$cert = fread($fp, 8192);
fclose($fp);
$pk2 = openssl_get_publickey($cert);

// seal message, only owners of $pk1 and $pk2 can decrypt $sealed with keys
// $ekeys[0] and $ekeys[1] respectively.
openssl_seal($data, $sealed, $ekeys, array($pk1, $pk2));

// free the keys from memory
openssl_free_key($pk1);
openssl_free_key($pk2);
?>

Changelog

描述

5.3.0

方法参数已添加。

另请参阅

  • openssl_open() - Open sealed data

← openssl_random_pseudo_bytes

openssl_sign →

扫码关注腾讯云开发者

领取腾讯云代金券