Skip to content

Instantly share code, notes, and snippets.

@pacojp
Created December 2, 2011 08:43
Show Gist options
  • Save pacojp/1422375 to your computer and use it in GitHub Desktop.
Save pacojp/1422375 to your computer and use it in GitHub Desktop.
temp ruby openssl
openssl enc -d -aes-256-cbc -in encrypted -k jiji -base64
# -*- coding: utf-8 -*-
require 'openssl'
require 'base64'
text = 'rirakkuma' * 80 * 30000
pass = "jiji"
salt = OpenSSL::Random.random_bytes(8)
ci = OpenSSL::Cipher::Cipher.new('AES-256-CBC')
ci.encrypt
ci.pkcs5_keyivgen(pass, salt, 1)
a = ci.update(text)
b = ci.final
print Base64.encode64("Salted__" + salt + a + b )
openssl enc -e -aes-256-cbc -in source -out encrypted -k jiji -base64
# -*- coding: utf-8 -*-
require 'openssl'
require 'base64'
pass = "jiji"
data = nil
open('encrypted') do |f|
data = f.read
end
data = Base64.decode64(data)
p data
@cipher_text = data.unpack("a8a8a*")
p @cipher_text
pbes = OpenSSL::Cipher.new("aes-256-cbc")
pbes.pkcs5_keyivgen(
pass,
@cipher_text[1], # salt
1 # iteration count
# ,OpenSSL::Digest::MD5.new() # Hash function
)
pbes.decrypt()
plain_text = pbes.update(@cipher_text[2]) + pbes.final
print plain_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment