W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
openssl_seal — 密封 (加密) 數(shù)據(jù)
openssl_seal(
string $data,
string &$sealed_data,
array &$encrypted_keys,
array $public_key,
string $cipher_algo,
string &$iv = null
): int|false
openssl_seal() 使用隨機(jī)生成的密鑰和給定的 cipher_algo 方法密封(加密)data 數(shù)據(jù)。密鑰用與 public_key 中的標(biāo)識(shí)符相關(guān)聯(lián)的每個(gè)公共密鑰加密,并且每個(gè)加密密鑰在 encrypted_keys 中返回。這意味著一個(gè)人可以將密封的數(shù)據(jù)發(fā)送給多個(gè)接收者(如果一個(gè)人已經(jīng)獲得了他們的公鑰)。每個(gè)接收方都必須同時(shí)接收加密的數(shù)據(jù)和用接收方的公鑰加密的信封密鑰。
data
要密封的數(shù)據(jù)。
sealed_data
被密封后的數(shù)據(jù)。
encrypted_keys
已被加密的密鑰數(shù)組。
public_key
包含公鑰的 OpenSSLAsymmetricKey 實(shí)例數(shù)組。
cipher_algo
加密算法。
默認(rèn)值('RC4'
)認(rèn)為不安全。強(qiáng)烈建議明確指定安全密碼方法。
iv
初始化向量。
成功時(shí)返回密封后數(shù)據(jù)的長(zhǎng)度,錯(cuò)誤為 false。 如果密封后的數(shù)據(jù)成功地通過(guò) sealed_data 變量返回,那么信封密鑰也將會(huì)通過(guò) encrypted_keys 變量返回。
版本 | 說(shuō)明 |
---|---|
8.0.0 | public_key 現(xiàn)在接受 OpenSSLAsymmetricKey 實(shí)例 array;之前接受類(lèi)型 OpenSSL key 的 resource 數(shù)組。 |
8.0.0 | cipher_algo 不再是可選參數(shù)。 |
8.0.0 | iv 現(xiàn)在可為 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);
?>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: