Skip to content

Instantly share code, notes, and snippets.

@ckozus
Created August 8, 2018 14:11
Show Gist options
  • Save ckozus/402bbb2ae37c947d716a57d0138d5682 to your computer and use it in GitHub Desktop.
Save ckozus/402bbb2ae37c947d716a57d0138d5682 to your computer and use it in GitHub Desktop.
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