简体   繁体   中英

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

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.

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) {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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