PHP8 openssl_open

2024-03-12 12:00 更新

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

openssl_open — 打開密封的數(shù)據(jù)

說明

openssl_open(
    string $data,
    string &$output,
    string $encrypted_key,
    OpenSSLAsymmetricKey|OpenSSLCertificate|array|string $private_key,
    string $cipher_algo,
    ?string $iv = null
): bool

openssl_open() 使用與密鑰標識符 private_key 和信封密鑰 encrypted_key 相關(guān)聯(lián)的私鑰打開(解密)data 數(shù)據(jù), 使用解密后的數(shù)據(jù)填充 output。當數(shù)據(jù)被密封時,就生成了信封密鑰且只能由一個特定的私鑰使用。更多信息參見openssl_seal()。

參數(shù) 

data
output

如果調(diào)用成功,則在這個參數(shù)中返回打開的數(shù)據(jù)。

encrypted_key
private_key
cipher_algo

加解密算法。

警告

默認值('RC4')認為不安全。強烈建議明確指定安全密碼方法。

iv

初始化向量。

返回值 

成功時返回 true, 或者在失敗時返回 false。

更新日志 

版本說明
8.0.0private_key 現(xiàn)在接受 OpenSSLAsymmetricKey 或 OpenSSLCertificate 實例;之前接受類型 OpenSSL key 或 OpenSSL X.509 CSR 的 resource。
8.0.0cipher_algo 不再是可選參數(shù)。

示例 

示例 #1 openssl_open() 示例

<?php
// $sealed and $env_key are assumed to contain the sealed data
// and our envelope key, both given to us by the sealer.

// fetch private key from file and ready it
$fp = fopen("/src/openssl-0.9.6/demos/sign/key.pem", "r");
$priv_key = fread($fp, 8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key);

// decrypt the data and store it in $open
if (openssl_open($sealed, $open, $env_key, $pkeyid)) {
    echo "here is the opened data: ", $open;
} else {
    echo "failed to open data";
}

// free the private key from memory
openssl_free_key($pkeyid);
?>

參見 

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


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號