Skip to content

Instantly share code, notes, and snippets.

@emboss
Last active August 29, 2015 14:14
Show Gist options
  • Save emboss/255955b9bbff1a07c9fc to your computer and use it in GitHub Desktop.
Save emboss/255955b9bbff1a07c9fc to your computer and use it in GitHub Desktop.
==> openssl-build.bash <==
#!/bin/bash
set -e -x
export CFLAG="-g"
export CFLAGS="-g"
# Debugging Target
# debug-linux-elf-noefence
# SCTP broken; Linux missing SCTP_SENDER_DRY_EVENT
# sctp \
./Configure \
enable-idea \
enable-mdc2 \
enable-md2 \
enable-rc5 \
enable-rfc3779 \
enable-ssl2 \
enable-tlsext \
no-hw \
no-krb5 \
shared \
threads \
zlib \
--prefix=/usr/local/openssl \
--openssldir=/usr/local/openssl \
linux-x86_64
make depend
make
sudo make install
==> ruby-build.bash <==
#!/bin/bash
set -e -x
export CFLAGS="-g -I/usr/local/openssl/include"
export CCFLAGS="-g"
export CPPFLAGS="-g"
export CXXFLAGS="-g"
export LDFLAGS="-L/usr/local/openssl/lib -L/usr/local/openssl/lib/engines -Wl,-rpath=/usr/local/openssl/lib,-rpath=/usr/local/openssl/lib/engines"
export LD_RUN_PATH="/usr/local/openssl/lib:/usr/local/openssl/lib/engines"
./configure \
--with-static-linked-ext \
--prefix=/usr/local/ruby192 \
--enable-shared \
--with-ruby-version=full
make
sudo make install
==> ruby-openssl-test.rb <==
#!/usr/bin/env ruby
require 'openssl'
require 'digest/sha1'
def hex_display(str = "")
return "0x" << str.unpack("H*")[0]
end
payload = "test payload"
puts "raw: #{payload} [#{hex_display(payload)}]\n"
encryption = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
encryption.encrypt
encryption.key = key = Digest::SHA1.hexdigest("test password")
encryption.iv = iv = encryption.random_iv
ciphertext = encryption.update(payload)
ciphertext << encryption.final
puts "encrypted: [#{hex_display(ciphertext)}]\n"
decryption = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
decryption.decrypt
decryption.key = key
decryption.iv = iv
plaintext = decryption.update(ciphertext)
plaintext << decryption.final
puts "decrypted: #{plaintext} [#{hex_display(plaintext)}]\n"
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment