Last active
March 25, 2019 19:55
-
-
Save ianterrell/cead66638bbf4f2f0fa50cb8088f45c2 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
require 'securerandom' | |
require 'base64' | |
require 'uri' | |
# This is probably provided by a library in your language. | |
def encrypt(data) | |
salt = "" | |
8.times { salt << rand(255).chr } | |
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc") | |
cipher.encrypt | |
cipher.pkcs5_keyivgen($secret, salt, 1) | |
e = cipher.update(data) + cipher.final | |
e = "Salted__#{salt}#{e}" #OpenSSL compatible | |
Base64.encode64(e) | |
end | |
# This is probably provided by a library in your language. | |
def decrypt(data) | |
raise ArgumentError, 'Data is too short' unless data.length >= 16 | |
data = Base64.decode64(data) | |
salt = data[8..15] | |
data = data[16..-1] | |
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc") | |
cipher.decrypt | |
cipher.pkcs5_keyivgen($secret, salt, 1) | |
cipher.update(data) + cipher.final | |
end | |
# This is probably provided by a library in your language. | |
def url_encode(data) | |
URI.encode(data, /\W/) | |
end | |
email = "[email protected]" | |
first_name = "John" | |
last_name = "Doe" | |
partner_id = "johndoe11" | |
profession = "Nurse" | |
specialty = "Addiction Medicine" | |
time = Time.now.utc.to_s # => "2018-04-02 19:20:23 UTC" | |
# Note: | |
# All of the data payload values must be URL encoded! | |
data = "e=#{url_encode(email)}" # => "e=johndoe%40partner%2Ecom" | |
data << "&f=#{url_encode(first_name)}" | |
data << "&l=#{url_encode(last_name)}" | |
data << "&id=#{url_encode(partner_id)}" | |
data << "&p=#{url_encode(profession)}" | |
data << "&s=#{url_encode(specialty)}" | |
$secret = "t0ps3cr3t" | |
url = "https://archemedx.com/provides/this/url-per-activity" | |
# Note: | |
# The parameters must be URL encoded after they are encrypted! | |
url << "?t=#{url_encode(encrypt(time))}" | |
url << "&d=#{url_encode(encrypt(data))}" | |
puts url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment