class SecureYaml::Cipher

Public Instance Methods

decrypt(secret_key, encrypted_data) click to toggle source
# File lib/config/patch/secure_yaml/cipher.rb, line 14
def decrypt(secret_key, encrypted_data)
  cipher = create_cipher(secret_key, :decrypt)
  cipher.update(Base64.decode64(encrypted_data)) + cipher.final
end
encrypt(secret_key, plain_data) click to toggle source
# File lib/config/patch/secure_yaml/cipher.rb, line 9
def encrypt(secret_key, plain_data)
  cipher = create_cipher(secret_key, :encrypt)
  strip_newline_chars_from_base64(Base64.encode64(cipher.update(plain_data) + cipher.final))
end

Private Instance Methods

create_cipher(secret_key, type) click to toggle source
# File lib/config/patch/secure_yaml/cipher.rb, line 21
def create_cipher(secret_key, type)
  cipher = retrieve_encryption_type(type)
  cipher.key = Digest::SHA2.new(256).digest(secret_key)
  cipher
end
retrieve_encryption_type(type = :encrypt) click to toggle source
# File lib/config/patch/secure_yaml/cipher.rb, line 27
def retrieve_encryption_type(type = :encrypt)
  cipher = OpenSSL::Cipher.new("AES-256-CFB")
  type == :encrypt ? cipher.encrypt : cipher.decrypt
  cipher
end
strip_newline_chars_from_base64(base64) click to toggle source
# File lib/config/patch/secure_yaml/cipher.rb, line 33
def strip_newline_chars_from_base64(base64)
  base64.gsub("\n", '')
end