Class: DiceBag::PrivateKey
- Inherits:
-
Object
- Object
- DiceBag::PrivateKey
- Defined in:
- lib/dice_bag/private_key.rb
Constant Summary collapse
- @@header =
"-----BEGIN RSA PRIVATE KEY-----"
"-----END RSA PRIVATE KEY-----"
Instance Attribute Summary collapse
-
#private_key ⇒ Object
Returns the value of attribute private_key.
Instance Method Summary collapse
-
#initialize(key) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
- #is_valid_private_key? ⇒ Boolean
- #to_rsa_format! ⇒ Object
Constructor Details
#initialize(key) ⇒ PrivateKey
Returns a new instance of PrivateKey.
8 9 10 |
# File 'lib/dice_bag/private_key.rb', line 8 def initialize(key) @private_key = key end |
Instance Attribute Details
#private_key ⇒ Object
Returns the value of attribute private_key.
4 5 6 |
# File 'lib/dice_bag/private_key.rb', line 4 def private_key @private_key end |
Instance Method Details
#is_valid_private_key? ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dice_bag/private_key.rb', line 12 def is_valid_private_key? require 'openssl' begin OpenSSL::PKey::RSA.new @private_key return true rescue => e p e. p e.backtrace return false end end |
#to_rsa_format! ⇒ Object
24 25 26 27 28 29 |
# File 'lib/dice_bag/private_key.rb', line 24 def to_rsa_format! strip_down_key body = @private_key.split(/\s+/) body = body.first.scan(/.{1,64}/) if body.length == 1 @private_key = [@@header, body, @@footer].flatten.join("\n") end |