Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'base64'
- require 'openssl'
- bs = 192
- key_len = bs / 8
- iv_len = 16
- plain = "ilovethisgameZz"
- if ARGV.size == 2
- key = ARGV[0].split(' ').map { |i| Integer(i, 16) }.pack('C*')
- iv = ARGV[1].split(' ').map { |i| Integer(i, 16) }.pack('C*')
- else
- key = key_len.times.map { rand(256) }.pack('C*')
- iv = iv_len.times.map { rand(256) }.pack('C*')
- end
- cipher = OpenSSL::Cipher::AES.new(bs, :CBC)
- cipher.encrypt
- # key = cipher.random_key
- # iv = cipher.random_iv
- cipher.key = key
- cipher.iv = iv
- encrypted = cipher.update(plain) + cipher.final
- puts key.unpack('C*').map { |i| "%x" % i }.join(' ')
- puts iv.unpack('C*').map { |i| "%x" % i }.join(' ')
- puts Base64.encode64(encrypted)
Add Comment
Please, Sign In to add comment