简体   繁体   English

使用 (defuse php-encryption) 库加密和解密文件时出现问题

[英]Problem encrypting and decrypting files using (defuse php-encryption) library

I tried to encrypt a file in a laravel api proyect using https://github.com/defuse/php-encryption/ , the problem is that the file in question does not encrypt me, only the name of the fileno the content, so it does not help me at all我尝试使用https://github.com/defuse/php-encryption/在 laravel api proyect 中加密文件,问题是有问题的文件没有加密我,只有文件名没有内容,所以它根本没有帮助我

Storage::put('',$file);
$inputFilename=storage_path()."/app/public/";
$outputFilename=storage_path()."/app/public/";;
$key = Key::createNewRandomKey();

try {
    File::encryptFile($inputFilename, $outputFilename, $key);
} catch (EnvironmentIsBrokenException $e) {

} catch (IOException $e) {

}

and i'm not able to looking for a solution我无法寻找解决方案

在此处输入图片说明

You are attempting to encrypt a directory, not a file.您正在尝试加密目录,而不是文件。 Change the paths so that they represent a file.更改路径,使它们代表一个文件。

$inputFilename = storage_path() . '/app/public/file_to_encrypt.txt';
$outputFilename = storage_path() . '/app/public/encrypted_file.txt';

You are only passing the PATH to the enc function and not the actual file name.您只是将 PATH 传递给 enc 函数,而不是实际的文件名。

Storage::put('',$file);

$inputFilename=storage_path()."/app/public/";
$outputFilename=storage_path()."/app/public/";;
$key = Key::createNewRandomKey();

try {
    File::encryptFile(  $inputFilename.$file, 
                        $outputFilename.'EncryptedFileName', 
                        $key
                    );

} catch (EnvironmentIsBrokenException $e) {

} catch (IOException $e) {

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM