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.