Class: Snxvpn::RSA
- Inherits:
-
OpenSSL::PKey::RSA
- Object
- OpenSSL::PKey::RSA
- Snxvpn::RSA
- Defined in:
- lib/snxvpn/rsa.rb
Class Method Summary collapse
Instance Method Summary collapse
- #hex_encrypt(s) ⇒ Object
-
#initialize(mod, exp) ⇒ RSA
constructor
A new instance of RSA.
Constructor Details
#initialize(mod, exp) ⇒ RSA
Returns a new instance of RSA.
10 11 12 13 14 15 |
# File 'lib/snxvpn/rsa.rb', line 10 def initialize(mod, exp) pubkey = create_encoded_pubkey_from([mod].pack("H*"), [exp].pack("H*")) hexkey = [pubkey].pack("H*") pemkey = "-----BEGIN RSA PUBLIC KEY-----\n#{Base64.encode64 hexkey}-----END RSA PUBLIC KEY-----" super(pemkey) end |
Class Method Details
.parse(body) ⇒ Object
4 5 6 7 8 |
# File 'lib/snxvpn/rsa.rb', line 4 def self.parse(body) mod = body.match(/var *modulus *\= *\'(\w+)\'/).to_a[1] exp = body.match(/var *exponent *\= *\'(\w+)\'/).to_a[1] new(mod, exp) if mod && exp end |
Instance Method Details
#hex_encrypt(s) ⇒ Object
17 18 19 |
# File 'lib/snxvpn/rsa.rb', line 17 def hex_encrypt(s) public_encrypt(s).reverse.unpack("H*").first end |