Created
August 8, 2018 14:11
-
-
Save ckozus/402bbb2ae37c947d716a57d0138d5682 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = Attachment.first | |
digest = Paperclip::Attachment.default_options[:hash_digest] | |
secret = Paperclip::Attachment.default_options[:hash_secret] | |
data = "attachments/files/#{a.id}/original/#{a.updated_at.to_i}" | |
hash_for_attachment = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(digest).new, secret, data) | |
if a.file.url.include?(hash_for_attachment) | |
puts "correct hash: #{hash_for_attachment}" | |
else | |
puts "hash incorrect" | |
puts hash_for_attachment | |
puts a.file.url | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment