openssl_seal

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

openssl_seal密封 (加密) 数据

说明

openssl_seal(
    string $data,
    string &$sealed_data,
    array &$encrypted_keys,
    array $public_key,
    string $cipher_algo,
    string &$iv = null
): int|false

openssl_seal() 使用随机生成的密钥和给定的 cipher_algo 方法密封(加密)data 数据。密钥用与 public_key 中的标识符相关联的每个公共密钥加密,并且每个加密密钥在 encrypted_keys 中返回。这意味着一个人可以将密封的数据发送给多个接收者(如果一个人已经获得了他们的公钥)。每个接收方都必须同时接收加密的数据和用接收方的公钥加密的信封密钥。

参数

data

要密封的数据。

sealed_data

被密封后的数据。

encrypted_keys

已被加密的密钥数组。

public_key

包含公钥的 OpenSSLAsymmetricKey 实例数组。

cipher_algo

加密算法。

警告

默认值('RC4')认为不安全。强烈建议明确指定安全密码方法。

iv

初始化向量。

返回值

成功时返回密封后数据的长度,错误为 false。 如果密封后的数据成功地通过 sealed_data 变量返回,那么信封密钥也将会通过 encrypted_keys 变量返回。

更新日志

版本 说明
8.0.0 public_key 现在接受 OpenSSLAsymmetricKey 实例 array;之前接受类型 OpenSSL key资源(resource) 数组。
8.0.0 cipher_algo 不再是可选参数。
8.0.0 iv 现在可为 null。

范例

示例 #1 openssl_seal() 示例

<?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);
?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top