Module: Snapcat::Crypt

Extended by:
Crypt
Included in:
Crypt
Defined in:
lib/snapcat/crypt.rb

Constant Summary collapse

CIPHER =
'AES-128-ECB'
ENCRYPTION_KEY =
'M02cnQ51Ji97vwT4'

Instance Method Summary collapse

Instance Method Details

#decrypt(data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/snapcat/crypt.rb', line 8

def decrypt(data)
  cipher = OpenSSL::Cipher.new(CIPHER)
  cipher.decrypt
  cipher.key = ENCRYPTION_KEY
  decrypted_data = ''

  data.bytes.each_slice(16) do |slice|
    decrypted_data += cipher.update(slice.map(&:chr).join)
  end

  decrypted_data += cipher.final
end

#encrypt(data) ⇒ Object



21
22
23
24
25
26
# File 'lib/snapcat/crypt.rb', line 21

def encrypt(data)
  cipher = OpenSSL::Cipher.new(CIPHER)
  cipher.encrypt
  cipher.key = ENCRYPTION_KEY
  cipher.update(pkcs5_pad(data)) + cipher.final
end