Skip to content

Instantly share code, notes, and snippets.

Created September 12, 2013 19:53
What would you like to do?
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'base64'
require 'digest'
require 'openssl'
def encode(cryptkey, iv, cleardata)
cipher ='AES-256-CBC')
cipher.encrypt # set cipher to be encryption mode
cipher.key = cryptkey
cipher.iv = iv
encrypted = ''
encrypted << cipher.update(cleardata)
encrypted <<
def b64enc(data)
Base64.encode64(data).gsub(/\n/, '')
cryptkey = Digest::SHA256.digest('Nixnogen')
iv = 'a2xhcgAAAAAAAAAA'
buf = "Here is some data for the coding" # 32 chars
enc = encode(cryptkey, iv, buf)
puts "Encoded length: #{enc.length}"
puts "Encoded in Base64: " + b64enc(enc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment