Created
August 9, 2012 13:58
-
-
Save joshcom/3304431 to your computer and use it in GitHub Desktop.
RC4 crap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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