class SFax::Encryptor

Constants

DEFAULT_IV
OPEN_SSL_CIPHER

Attributes

iv[R]
key[R]

Public Class Methods

new(key:, iv: DEFAULT_IV) click to toggle source
# File lib/sfax/encryptor.rb, line 9
def initialize(key:, iv: DEFAULT_IV)
  @key = key.dup
  @iv = iv
end

Public Instance Methods

encrypt(plain) click to toggle source
# File lib/sfax/encryptor.rb, line 16
def encrypt(plain)
  cipher = new_encrypt_cipher

  encrypted_data = cipher.update plain
  encrypted_data << cipher.final

  Base64.encode64 encrypted_data
end
new_encrypt_cipher() click to toggle source
# File lib/sfax/encryptor.rb, line 25
def new_encrypt_cipher
  OpenSSL::Cipher::Cipher.new(OPEN_SSL_CIPHER).tap do |c|
    c.encrypt

    c.key = key
    c.iv = iv
  end
end