首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

openssl_open

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

openssl_open — 打开密封数据

描述

代码语言:javascript
复制
bool openssl_open ( string $sealed_data , string &$open_data , string $env_key , mixed $priv_key_id [, string $method = "RC4" [, string &$iv ]] )

openssl_open()sealed_data使用与密钥标识符priv_key_id和信封密钥相关联的私钥打开(解密)env_key,并填充open_data解密的数据。信封密钥是在密封数据时生成的,只能由一个特定的私钥使用。有关更多信息,请参阅openssl_seal()。

参数

sealed_data open_data

如果调用成功,则在此参数中返回已打开的数据。

env_key priv_key_id method

密码方法。

iv

初始化向量。

返回值

成功返回TRUE或失败时返回FALSE

更新日志

描述

7.0.0

iv已被添加。

5.3.0

该方法已添加。

例子

示例#1 openssl_open()示例

代码语言:javascript
复制
<?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);
?>

扫码关注腾讯云开发者

领取腾讯云代金券