Class: Ciri::Key
- Inherits:
-
Object
- Object
- Ciri::Key
- Defined in:
- lib/ciri/key.rb
Overview
Instance Attribute Summary collapse
-
#ec_key ⇒ Object
readonly
Returns the value of attribute ec_key.
Class Method Summary collapse
Instance Method Summary collapse
- #ecdsa_signature(data) ⇒ Object
- #ecies_decrypt(data, shared_mac_data = '') ⇒ Object
- #ecies_encrypt(message, shared_mac_data = '') ⇒ Object
-
#initialize(ec_key: nil, raw_public_key: nil, raw_private_key: nil) ⇒ Key
constructor
initialized from ec_key or raw keys ec_key is a OpenSSL::PKey::EC object, raw keys is bytes presented keys.
-
#raw_public_key ⇒ Object
raw public key.
Constructor Details
#initialize(ec_key: nil, raw_public_key: nil, raw_private_key: nil) ⇒ Key
initialized from ec_key or raw keys ec_key is a OpenSSL::PKey::EC object, raw keys is bytes presented keys
56 57 58 |
# File 'lib/ciri/key.rb', line 56 def initialize(ec_key: nil, raw_public_key: nil, raw_private_key: nil) @ec_key = ec_key || Ciri::Utils.create_ec_pk(raw_privkey: raw_private_key, raw_pubkey: raw_public_key) end |
Instance Attribute Details
#ec_key ⇒ Object (readonly)
Returns the value of attribute ec_key.
52 53 54 |
# File 'lib/ciri/key.rb', line 52 def ec_key @ec_key end |
Class Method Details
.ecdsa_recover(msg, signature) ⇒ Object
40 41 42 43 |
# File 'lib/ciri/key.rb', line 40 def ecdsa_recover(msg, signature) raw_public_key = Crypto.ecdsa_recover(msg, signature, return_raw_key: true) Ciri::Key.new(raw_public_key: raw_public_key) end |
Instance Method Details
#ecdsa_signature(data) ⇒ Object
65 66 67 |
# File 'lib/ciri/key.rb', line 65 def ecdsa_signature(data) Crypto.ecdsa_signature(secp256k1_key, data) end |
#ecies_decrypt(data, shared_mac_data = '') ⇒ Object
73 74 75 |
# File 'lib/ciri/key.rb', line 73 def ecies_decrypt(data, shared_mac_data = '') Crypto.ecies_decrypt(data, ec_key, shared_mac_data) end |
#ecies_encrypt(message, shared_mac_data = '') ⇒ Object
69 70 71 |
# File 'lib/ciri/key.rb', line 69 def ecies_encrypt(, shared_mac_data = '') Crypto.ecies_encrypt(, ec_key, shared_mac_data) end |
#raw_public_key ⇒ Object
raw public key
61 62 63 |
# File 'lib/ciri/key.rb', line 61 def raw_public_key @raw_public_key ||= ec_key.public_key.to_bn.to_s(2) end |