I am encrypting documents before they are added to the media library like so:
$documentUploaded = $company->addMediaFromBase64(Crypt::encryptString($file))->usingFileName($file->getClientOriginalName())->toMediaCollection();
The contents of the encrypted file looks like this:
{"iv":"OEgwSuY7eBy202fE9ZdxKw==","value":"We2UcDvODKDv+iVV8wiCuiZqaho8UV83JjyXhV\/6\/X8=","mac":"b9e7967ad0f38c9064958070a3bea97f5463043bf27a4a6c8aee624d997fd4a2"}
Then when I retrieve the documents I try and decrypt them so they can be sent to the client in a response:
$media->transform(function ($taskMedia, $taskMediaIndex) {
$taskMedia = Crypt::decrypt(file_get_contents($taskMedia->getPath()));
return $taskMedia;
});
But I keep getting the following error:
local.ERROR: The payload is invalid.
Full stack trace:
[2018-05-16 09:22:05] local.ERROR: The payload is invalid. {"userId":1,"email":"admin@example.com","exception":"[object] (Illuminate\\Contracts\\Encryption\\DecryptException(code: 0): The payload is invalid. at C:\\wamp\\www\\astrid-api-post-mvp\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\Encrypter.php:191)
[stacktrace]
#0 C:\\wamp\\www\\astrid-api-post-mvp\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\Encrypter.php(134): Illuminate\\Encryption\\Encrypter->getJsonPayload(NULL)
#1 C:\\wamp\\www\\astrid-api-post-mvp\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php(221): Illuminate\\Encryption\\Encrypter->decrypt('{\"iv\":\"1rSma+x8...')
#2 C:\\wamp\\www\\astrid-api-post-mvp\\app\\Services\\CompanyService.php(243): Illuminate\\Support\\Facades\\Facade::__callStatic('decrypt', Array)
#3 [internal function]: App\\Services\\CompanyService->App\\Services\\{closure}(Object(Spatie\\MediaLibrary\\Models\\Media), 0)
#4 C:\\wamp\\www\\astrid-api-post-mvp\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Collection.php(932): array_map(Object(Closure), Array, Array)
#5 C:\\wamp\\www\\astrid-api-post-mvp\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Collection.php(164): Illuminate\\Support\\Collection->map(Object(Closure))
#6 C:\\wamp\\www\\astrid-api-post-mvp\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Collection.php(1600): Illuminate\\Database\\Eloquent\\Collection->map(Object(Closure))
#7 C:\\wamp\\www\\astrid-api-post-mvp\\app\\Services\\CompanyService.php(246): Illuminate\\Support\\Collection->transform(Object(Closure))
#8 C:\\wamp\\www\\astrid-api-post-mvp\\app\\Http\\Controllers\\Api\\CompaniesController.php(123): App\\Services\\CompanyService->documents()
#9 [internal function]: App\\Http\\Controllers\\Api\\CompaniesController->documents()
What am I doing wrong here?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire