Class: WeWhisper::Cryptor

Inherits:
Object
  • Object
show all
Includes:
Cipher
Defined in:
lib/we_whisper/cryptor.rb

Constant Summary

Constants included from Cipher

WeWhisper::Cipher::BLOCK_SIZE, WeWhisper::Cipher::CIPHER

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cipher

#cipher_decrypt, #cipher_encrypt, #pack, #unpack

Constructor Details

#initialize(content) ⇒ Cryptor

Returns a new instance of Cryptor.



17
18
19
20
# File 'lib/we_whisper/cryptor.rb', line 17

def initialize(content)
  @value = content
  self
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/we_whisper/cryptor.rb', line 7

def value
  @value
end

Class Method Details

.decrypt(encrypted_content, encoding_aes_key) ⇒ Object



13
14
15
# File 'lib/we_whisper/cryptor.rb', line 13

def self.decrypt(encrypted_content, encoding_aes_key)
  new(encrypted_content).decrypt(encoding_aes_key)
end

.encrypt(content, appid, encoding_aes_key) ⇒ Object



9
10
11
# File 'lib/we_whisper/cryptor.rb', line 9

def self.encrypt(content, appid, encoding_aes_key)
  new(content).encrypt(appid, encoding_aes_key)
end

Instance Method Details

#decrypt(encoding_aes_key) ⇒ Object



29
30
31
32
33
34
# File 'lib/we_whisper/cryptor.rb', line 29

def decrypt(encoding_aes_key)
  decode()
    .decrypt_with_aes_key(encoding_aes_key)
    .unpack_with_appid()
    .value
end

#encrypt(appid, encoding_aes_key) ⇒ Object



22
23
24
25
26
27
# File 'lib/we_whisper/cryptor.rb', line 22

def encrypt(appid, encoding_aes_key)
  pack_with_appid(appid)
    .encrypt_with_aes_key(encoding_aes_key)
    .encode()
    .value
end