Class: Capsium::Protector
- Inherits:
-
Object
- Object
- Capsium::Protector
- Defined in:
- lib/capsium/protector.rb
Instance Method Summary collapse
- #apply_encryption_and_sign ⇒ Object
-
#initialize(package, encryption_metadata = nil, digital_signature_metadata = nil) ⇒ Protector
constructor
A new instance of Protector.
- #verify_signature ⇒ Object
Constructor Details
#initialize(package, encryption_metadata = nil, digital_signature_metadata = nil) ⇒ Protector
Returns a new instance of Protector.
10 11 12 13 14 15 |
# File 'lib/capsium/protector.rb', line 10 def initialize(package, = nil, = nil) @package = package @encryption_metadata = @digital_signature_metadata = end |
Instance Method Details
#apply_encryption_and_sign ⇒ Object
17 18 19 20 |
# File 'lib/capsium/protector.rb', line 17 def apply_encryption_and_sign encrypted_file = apply_encryption if @encryption_metadata sign_package(encrypted_file) if @digital_signature_metadata end |
#verify_signature ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/capsium/protector.rb', line 22 def verify_signature signature_data = JSON.parse(File.read(signature_file_path)) public_key = OpenSSL::PKey::RSA.new(File.read(public_key_path)) digest = OpenSSL::Digest.new(signature_data["algorithm"]) data = combined_data signature = Base64.decode64(signature_data["signature"]) public_key.verify(digest, signature, data) end |