Class: Travis::Encrypt::Base
- Inherits:
-
Object
- Object
- Travis::Encrypt::Base
- Defined in:
- lib/travis/encrypt/base.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #add_iv(string, iv) ⇒ Object
- #create_aes(mode = :encrypt, key, iv) ⇒ Object
- #create_iv ⇒ Object
- #decode(str) ⇒ Object
- #encode(str) ⇒ Object
- #extract_iv(string) ⇒ Object
-
#initialize(string, options) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(string, options) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 |
# File 'lib/travis/encrypt/base.rb', line 6 def initialize(string, ) @string = string @key = [:key] @options = validate end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/travis/encrypt/base.rb', line 4 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/travis/encrypt/base.rb', line 4 def @options end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
4 5 6 |
# File 'lib/travis/encrypt/base.rb', line 4 def string @string end |
Instance Method Details
#add_iv(string, iv) ⇒ Object
26 27 28 |
# File 'lib/travis/encrypt/base.rb', line 26 def add_iv(string, iv) "#{string}#{iv}" end |
#create_aes(mode = :encrypt, key, iv) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/travis/encrypt/base.rb', line 13 def create_aes(mode = :encrypt, key, iv) key = key[0, 32] # https://github.com/ruby/ruby/commit/ce635262f53b760284d56bb1027baebaaec175d1 aes = OpenSSL::Cipher::AES.new(256, :CBC) aes.send(mode) aes.key = key aes.iv = iv aes end |
#create_iv ⇒ Object
22 23 24 |
# File 'lib/travis/encrypt/base.rb', line 22 def create_iv SecureRandom.hex(8) end |
#decode(str) ⇒ Object
38 39 40 |
# File 'lib/travis/encrypt/base.rb', line 38 def decode(str) Base64.strict_decode64(str) end |
#encode(str) ⇒ Object
34 35 36 |
# File 'lib/travis/encrypt/base.rb', line 34 def encode(str) Base64.strict_encode64(str) end |
#extract_iv(string) ⇒ Object
30 31 32 |
# File 'lib/travis/encrypt/base.rb', line 30 def extract_iv(string) [string[-16..-1], string[0..-17]] end |