[英]encrypt file with php and public key
我生成了一個密鑰對(公共和私有),並從控制台生成:
openssl smime -encrypt -aes256 -in backup.sql -binary -DEM -out outform backup_encrypted.sql public_key.pem
我正確加密文件。 Sql,我可以用php做到這一點嗎? 我已經嘗試了幾種功能
我留下其中一個。
$data=file_get_contents("backup.sql");
$key=file_get_contents("public_key.pem");
openssl_public_encrypt($data,$output,$key);
echo $output;
$ output什么都不返回..謝謝。
請查看手冊 ,您必須提供公鑰的路徑 :
$data=file_get_contents("backup.sql");
$key="file://path/to/public_key.pem";
openssl_public_encrypt($data,$output,$key);
echo $output;
你可以使用file_get_contents(),例如:
$data=file_get_contents("backup.sql");
$key= file_get_contents('public_key.pem');
openssl_public_encrypt($data,$output,$key);
echo $output;
我檢查了這個片段和它的工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.