Method: Wework::Cipher#encrypt

Defined in:
lib/wework/cipher.rb

#encrypt(plain, encoding_aes_key) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/wework/cipher.rb', line 22

def encrypt(plain, encoding_aes_key)
  cipher = OpenSSL::Cipher.new(CIPHER)
  cipher.encrypt

  cipher.padding = 0
  key_data = Base64.decode64(encoding_aes_key + '=')
  cipher.key = key_data
  cipher.iv = [key_data].pack('H*')

  cipher.update(plain) + cipher.final
end