Skip to content

Instantly share code, notes, and snippets.

@halan
Last active June 5, 2016 13:44
Show Gist options
  • Save halan/c283507c8baf7a96beb9af12b153d53b to your computer and use it in GitHub Desktop.
Save halan/c283507c8baf7a96beb9af12b153d53b to your computer and use it in GitHub Desktop.
This small ruby can decrypt AES-CBC encrypted at https://jsfiddle.net/kq8Lfpar/7/
require 'openssl'
require 'base64'
puts 'Go to https://jsfiddle.net/kq8Lfpar/7/ and encrypt some text for decrypt here'
print 'Password: '
password = gets.chomp
print 'Encrypted: '
encrypted = gets.chomp
salt, iv, cipher = encrypted.split('.').map{|s| Base64.decode64(s) }
key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(password, salt, 100, 256)
aes = OpenSSL::Cipher::Cipher.new('AES-256-CBC')
aes.decrypt
aes.key = key
aes.iv = iv
print aes.update(cipher)
puts aes.final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment