Class: Stenohttp2::Common::CipherBuilder
- Inherits:
-
Object
- Object
- Stenohttp2::Common::CipherBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/stenohttp2/common/cipher_builder.rb
Constant Summary collapse
- DEFAULT_SALT =
OpenSSL::Random.random_bytes(16)
"\xCA|k\xC3Qw(\xB1E\xF3<\xA7\xCC\x96$\x8A".freeze
- DEFAULT_PASSWORD =
don't try this at home
'this is a secret'.freeze
- CIPHER_TYPE =
'AES-256-CFB'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(encryptor: true) ⇒ CipherBuilder
constructor
A new instance of CipherBuilder.
Constructor Details
#initialize(encryptor: true) ⇒ CipherBuilder
Returns a new instance of CipherBuilder.
26 27 28 |
# File 'lib/stenohttp2/common/cipher_builder.rb', line 26 def initialize(encryptor: true) @encryptor = encryptor end |
Class Method Details
.decryptor ⇒ Object
20 21 22 |
# File 'lib/stenohttp2/common/cipher_builder.rb', line 20 def decryptor new(encryptor: false).build end |
.encryptor ⇒ Object
16 17 18 |
# File 'lib/stenohttp2/common/cipher_builder.rb', line 16 def encryptor new(encryptor: true).build end |
Instance Method Details
#build ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/stenohttp2/common/cipher_builder.rb', line 31 def build cipher = OpenSSL::Cipher.new(CIPHER_TYPE) encryptor ? cipher.encrypt : cipher.decrypt cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1( DEFAULT_PASSWORD, DEFAULT_SALT, 20_000, cipher.key_len ) cipher end |