Skip to content

Instantly share code, notes, and snippets.

@joshcom
Created August 9, 2012 13:58
Show Gist options
  • Save joshcom/3304431 to your computer and use it in GitHub Desktop.
Save joshcom/3304431 to your computer and use it in GitHub Desktop.
RC4 crap
def encrypt str
c = OpenSSL::Cipher::Cipher.new("rc4")
c.encrypt
c.key = secret_key
e = c.update( str )
e << c.final
# Make it purdy. Useful for database storage.
e.unpack("H*")[0]
end
def decrypt enc_str
# Unmake it purdy.
enc_str = [enc_str].pack("H*")
c = OpenSSL::Cipher::Cipher.new("rc4")
c.decrypt
c.key = secret_key # Note, this is plain text, not hex, etc.
c.padding = 0
d = c.update( enc_str )
d << c.final
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment