Class: Uits::RSA2048
- Inherits:
-
Object
- Object
- Uits::RSA2048
- Defined in:
- lib/uits.rb
Instance Method Summary collapse
-
#initialize(path, passphrase) ⇒ RSA2048
constructor
A new instance of RSA2048.
- #signature(data) ⇒ Object
- #varify?(sign, data) ⇒ Boolean
Constructor Details
#initialize(path, passphrase) ⇒ RSA2048
51 52 53 54 55 56 57 58 |
# File 'lib/uits.rb', line 51 def initialize(path, passphrase) path.gsub!(/[^0-9A-Za-z]/, '') @passphrase = passphrase @private_key_path = File.join(Rails.root.to_s, "lib/.rsa", path, "id_rsa") @public_key_path = File.join(Rails.root.to_s, "lib/.rsa", path, "id_rsa.pub") @private_key = private_key @public_key = public_key end |
Instance Method Details
#signature(data) ⇒ Object
60 61 62 |
# File 'lib/uits.rb', line 60 def signature(data) Base64.encode64(@private_key.sign(OpenSSL::Digest::SHA1.new, data)) end |
#varify?(sign, data) ⇒ Boolean
64 65 66 67 |
# File 'lib/uits.rb', line 64 def varify?(sign, data) sign = Base64.decode64(sign) @public_key.verify(OpenSSL::Digest::SHA1.new, sign, data) end |