Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created February 10, 2015 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typeoneerror/cb974f4e08256b7e9ff8 to your computer and use it in GitHub Desktop.
Save typeoneerror/cb974f4e08256b7e9ff8 to your computer and use it in GitHub Desktop.
encyrptionish
require 'openssl'
def process_token_encryption(token)
raise ArgumentError, 'Cipher block not provided' unless block_given?
cipher = OpenSSL::Cipher::AES.new(128, :CBC)
yield cipher
cipher.pkcs5_keyivgen('password', '8 octets')
encrypted = cipher.update(token)
encrypted << cipher.final
encrypted
end
def encrypt_token(token)
process_token_encryption token do |cipher|
cipher.encrypt
end
end
def decrypt_token(token)
process_token_encryption token do |cipher|
cipher.decrypt
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment