Class: Fastlane::Helper::EncryptionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/helper/encryption_helper.rb

Defined Under Namespace

Modules: OperationType

Class Method Summary collapse

Class Method Details

.cipher(op_type) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/encryption_helper.rb', line 11

def self.cipher(op_type)
  cipher = OpenSSL::Cipher.new('aes-256-cbc')

  cipher.encrypt if op_type == OperationType::ENCRYPT
  cipher.decrypt if op_type == OperationType::DECRYPT

  cipher
end

.decrypt(encrypted, key) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/encryption_helper.rb', line 33

def self.decrypt(encrypted, key)
  cipher = cipher(OperationType::DECRYPT)
  cipher.key = key

  decrypted = cipher.update(encrypted)
  decrypted << cipher.final

  # Ensure consistent encoding
  decrypted.force_encoding(Encoding::UTF_8)

  decrypted
end

.encrypt(plain_text, key) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/encryption_helper.rb', line 20

def self.encrypt(plain_text, key)
  # Ensure consistent encoding
  plain_text.force_encoding(Encoding::UTF_8)

  cipher = cipher(OperationType::ENCRYPT)
  cipher.key = key

  encrypted = cipher.update(plain_text)
  encrypted << cipher.final

  encrypted
end

.generate_keyObject



46
47
48
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/encryption_helper.rb', line 46

def self.generate_key
  cipher(OperationType::ENCRYPT).random_key
end