ImageWizard icon indicating copy to clipboard operation
ImageWizard copied to clipboard

Encrypting the URL

Open papakojo opened this issue 3 years ago • 1 comments

Great library! I looked at your 'How to use it' and the 'unsafe' works as described but when options.Key = Encoding.UTF8.GetBytes("some key"); is set on the service and/or client, and the url is encrypted based on your format with the key and url value, all the request ends up in 'Signature is not valid!' error.

Can there be a description of how to add signature to external urls via a method? i.e. If the images are called from S3 or cloud storage? Not clear if that be done via the UrlBuilder based on the notes provided.

papakojo avatar Jul 09 '23 19:07 papakojo

Do you set the same key to backend and client?

Backend:

services.AddImageWizard(options => 
 {                          
     options.Key = new byte[64] { .. };
 }

Client:

services.AddImageWizardClient(options => 
{
    options.Key = new byte[64] { .. };
});

The default implementation of the signature service use HMACSHA256.

https://github.com/usercode/ImageWizard/blob/acb4892ff76ed9fdf2eb064921489a5ea8c5ca39/src/ImageWizard.Utils/Signature/HMACSHA256UrlSignature.cs#L61-L106

The signature is not relevant for the loader, which gets the original image from file, http, AWS or Azure.

There is a sample plugin for AWS, but I never tested it.

https://github.com/usercode/ImageWizard/tree/main/src/ImageWizard.AWS

The url builder already contains methods for Azure and AWS.

Example: https://github.com/usercode/ImageWizard/blob/main/src/ImageWizard.Client/Builder/DeliveryTypeExtensions.cs

usercode avatar Jul 10 '23 20:07 usercode