= 4.0.4, PHP 5, PHP 7, PHP 8)openssl_seal — 密封 (加密) 數(shù)據(jù)說(shuō)明openssl_seal( string $data, string &$sealed_data, array &$env_key">
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
openssl_seal — 密封 (加密) 數(shù)據(jù)
$data,&$sealed_data,&$env_keys,$pub_key_ids,$method = "RC4",&$iv = ?
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ù)和用接收方的公鑰加密的信封密鑰。
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($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);
?>