= 4.0.4, PHP 5, PHP 7, PHP 8)openssl_seal — 密封 (加密) 數(shù)據(jù)說(shuō)明openssl_seal( string $data, string &$sealed_data, array &$env_key">

openssl_seal

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

openssl_seal密封 (加密) 數(shù)據(jù)

說(shuō)明

openssl_seal(
    string $data,
    string &$sealed_data,
    array &$env_keys,
    array $pub_key_ids,
    string $method = "RC4",
    string &$iv = ?
): int

openssl_seal() 使用隨機(jī)生成的密鑰和給定的 method 方法密封 (加密) data 數(shù)據(jù)。 密鑰用與pub_key_ids中的標(biāo)識(shí)符相關(guān)聯(lián)的每個(gè)公共密鑰加密,并且每個(gè)加密密鑰在env_keys中返回。 這意味著一個(gè)人可以將密封的數(shù)據(jù)發(fā)送給多個(gè)接收者(如果一個(gè)人已經(jīng)獲得了他們的公鑰)。每個(gè)接收方都必須同時(shí)接收加密的數(shù)據(jù)和用接收方的公鑰加密的信封密鑰。

參數(shù)

data

要密封的數(shù)據(jù)。

sealed_data

被密封后的數(shù)據(jù)。

env_keys

已被加密的密鑰數(shù)組。

pub_key_ids

公鑰資源標(biāo)識(shí)符組成的數(shù)組。

method

加密算法。

iv

初始化向量。

返回值

成功,返回密封后數(shù)據(jù)的長(zhǎng)度,錯(cuò)誤,返回 false . 如果密封后的數(shù)據(jù)成功地通過(guò)sealed_data變量返回,那么信封密鑰也將會(huì)通過(guò) env_keys 變量返回。

更新日志

版本 說(shuō)明
7.0.0 添加 iv 變量。
5.3.0 添加 method 變量。

范例

示例 #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($fp8192);
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($fp8192);
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);
?>

參見(jiàn)