openssl_seal
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
openssl_seal — 密封 (加密) 數據
說明
   openssl_seal(
string
string
array
array
string
string
): int
  string
$data,string
&$sealed_data,array
&$env_keys,array
$pub_key_ids,string
$method = "RC4",string
&$iv = ?): int
   openssl_seal() 使用隨機產生的金鑰和給定的 method 方法密封 (加密)
   data 數據。 金鑰用與pub_key_ids中的識別符號相關聯的每個公共金鑰加密,並且每個加密金鑰在env_keys中返回。 這意味著一個人可以將密封的數據發送給多個接收者(如果一個人已經獲得了他們的公鑰)。每個接收方都必須同時接收加密的數據和用接收方的公鑰加密的信封金鑰。
  
參數
- 
data
- 
      要密封的數據。 
- 
sealed_data
- 
      被密封后的數據。 
- 
env_keys
- 
      已被加密的金鑰陣列。 
- 
pub_key_ids
- 
      公鑰資源識別符號組成的陣列。 
- 
method
- 
      加密演算法。 
- 
iv
- 
      初始化向量。 
返回值
   成功,返回密封后數據的長度,錯誤,返回 false .
   如果密封后的數據成功地通過sealed_data變數返回,那麼信封金鑰也將會通過 env_keys 變數返回。
  
更新日誌
| 版本 | 說明 | 
|---|---|
| 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);
?>