Created
January 6, 2017 07:31
-
-
Save mguezuraga/1d71cbfbaa516ef956d4108ad9bae43f 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 'openssl' | |
require 'digest/sha1' | |
require 'base64' | |
@key = Digest::SHA1.hexdigest('74cf0e9a3c2b904e9c445771cdccb3e6ce3e4da7') | |
@cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc') | |
def encrypt(data) | |
@cipher.encrypt | |
@cipher.key = @key | |
rc = @cipher.update(data) | |
rc << @cipher.final | |
return rc | |
end | |
def decrypt(data) | |
@cipher.decrypt | |
@cipher.key = @key | |
rc = @cipher.update(Base64::decode64(data)) | |
rc << @cipher.final | |
return rc | |
end | |
token_txt = "serveradmin:bob:1234567" | |
token = encrypt(token_txt) | |
token64 = Base64::encode64(token).strip.delete("\n") | |
puts "Encrypted text (base64): #{token64}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment