1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-23 11:14:48 +02:00
imgproxy/examples/signature.ex

22 lines
587 B
Elixir
Raw Normal View History

2017-11-13 21:48:31 +11:00
defmodule App.Imgproxy do
@key Base.decode16!("943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881", case: :lower)
@salt Base.decode16!("520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5", case: :lower)
2017-11-13 21:48:31 +11:00
2022-09-03 00:54:11 +06:00
def sign_path(path) do
2017-11-13 21:48:31 +11:00
signature = gen_signature(path)
2022-09-03 00:54:11 +06:00
Path.join(["/", signature, path])
2017-11-13 21:48:31 +11:00
end
defp gen_signature(path) do
:sha256
|> :crypto.hmac(@key, @salt <> path)
|> Base.url_encode64(padding: false)
end
end
# Usage
#
2022-09-03 00:54:11 +06:00
# App.Imgproxy.sign_path(
# "/rs:fit:300:300/plain/https://myawesomedomain.com/raw-image.png"
2017-11-13 21:48:31 +11:00
# )