1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-02-12 11:46:10 +02:00
imgproxy/examples/signature.rb

15 lines
521 B
Ruby
Raw Normal View History

2017-07-04 18:17:20 +06:00
require "openssl"
require "base64"
key = ["943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881"].pack("H*")
salt = ["520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5"].pack("H*")
2022-09-03 00:54:11 +06:00
path = "/rs:fit:300:300/plain/http://img.example.com/pretty/image.jpg"
2017-07-04 18:17:20 +06:00
digest = OpenSSL::Digest.new("sha256")
# You can trim padding spaces to get good-looking url
hmac = Base64.urlsafe_encode64(OpenSSL::HMAC.digest(digest, key, "#{salt}#{path}")).tr("=", "")
signed_path = "/#{hmac}#{path}"
2022-09-03 00:54:11 +06:00
puts signed_path