Created
February 10, 2015 14:56
-
-
Save typeoneerror/cb974f4e08256b7e9ff8 to your computer and use it in GitHub Desktop.
encyrptionish
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 '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