class Origami::Encryption::RC4

Class wrapper for the RC4 algorithm.

Public Class Methods

decrypt(key, data) click to toggle source

Decrypts data using the given key

# File lib/origami/encryption.rb, line 537
def RC4.decrypt(key, data)
    RC4.new(key).decrypt(data)
end
encrypt(key, data) click to toggle source

Encrypts data using the given key

# File lib/origami/encryption.rb, line 530
def RC4.encrypt(key, data)
    RC4.new(key).encrypt(data)
end
new(key) click to toggle source

Creates and initialises a new RC4 generator using given key

# File lib/origami/encryption.rb, line 544
def initialize(key)
    @key = key
end

Public Instance Methods

cipher(data) click to toggle source

Encrypt/decrypt data with the RC4 encryption algorithm

# File lib/origami/encryption.rb, line 551
def cipher(data)
    return '' if data.empty?

    rc4 = OpenSSL::Cipher::RC4.new.encrypt
    rc4.key_len = @key.length
    rc4.key = @key

    rc4.update(data) + rc4.final
end
Also aliased as: encrypt, decrypt
decrypt(data)
Alias for: cipher
encrypt(data)
Alias for: cipher