Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'socket'
- require 'openssl'
- require 'rubygems'
- require 'net/ssh'
- #ssh/encryption config
- HOST = '192.168.1.113'
- USER = 'username'
- PASS = 'password'
- KEY = "qwertyuiopasdfghjklzxcvbnmqwerty"
- IV = "qwertyuiopasdfghjklzxcvbnmqwerty"
- PREAMBLE="begin_encryption"
- class Encryption
- def initialize (string)
- @string = string
- end
- #encrypts
- def encrypt_payload
- cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
- cipher.encrypt
- cipher.key = ::KEY
- cipher.iv = ::IV
- cipher.update(@string) + cipher.final
- end
- #decrypts
- def decrypt_payload
- cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
- cipher.decrypt
- cipher.key = ::KEY
- cipher.iv = ::IV
- cipher.update(@string) + cipher.final
- end
- end
- #this is a socket client to tx/rx streamimg aes-256 encrypted data.
- class Socket_IO_crypt
- def initialize(data, port, host)
- @io_obj = data
- @port = port
- @host = host
- end
- def server
- server = TCPServer.open( @host , @port)
- loop {
- rx = server.accept
- #scans for a preamble and decrypts string sending it to a handler
- encrypted_str = rx.to_s.gsub(::PREAMBLE , "")
- p rx.to_s + "reciever"
- p encrypted_str + "encrypted"
- decrypted_str = Encryption.new(encrypted_str)
- print decrypted_str + "decrypted"
- rx.close
- }
- end
- #listens for incomming connections on @port sending a encrypted string with a preamble
- #shoots an encrypted message to @host atc @port with preamble
- def client
- tx = TCPSocket.open(@host, @port)
- data = Encryption.new(@io_obj)
- crypt_data = data.encrypt_payload
- p ::PREAMBLE + crypt_data
- tx.send ::PREAMBLE + crypt_data
- tx.close
- end
- end
- asdf = Socket_IO_crypt.new(" Hello World" , "5554" , "127.0.0.1")
- asdf.client
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement