Class: OMQ::Blake3ZMQ::Crypto::PrivateKey
- Inherits:
-
Object
- Object
- OMQ::Blake3ZMQ::Crypto::PrivateKey
- Defined in:
- lib/omq/blake3zmq/crypto.rb
Overview
X25519 private key wrapper with key generation and Diffie-Hellman.
Class Method Summary collapse
-
.generate ⇒ PrivateKey
Generates a new random private key.
Instance Method Summary collapse
-
#diffie_hellman(peer_public_key) ⇒ String
Performs X25519 Diffie-Hellman with a peer’s public key.
-
#initialize(bytes) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
-
#public_key ⇒ PublicKey
Returns the corresponding public key.
-
#to_s ⇒ String
Returns the raw 32-byte secret key.
Constructor Details
#initialize(bytes) ⇒ PrivateKey
Returns a new instance of PrivateKey.
51 52 53 |
# File 'lib/omq/blake3zmq/crypto.rb', line 51 def initialize(bytes) @key = X25519::Scalar.new(bytes.b) end |
Class Method Details
.generate ⇒ PrivateKey
Generates a new random private key.
45 46 47 |
# File 'lib/omq/blake3zmq/crypto.rb', line 45 def self.generate new(X25519::Scalar.generate.to_bytes) end |
Instance Method Details
#diffie_hellman(peer_public_key) ⇒ String
Performs X25519 Diffie-Hellman with a peer’s public key.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/omq/blake3zmq/crypto.rb', line 76 def diffie_hellman(peer_public_key) pk = case peer_public_key when PublicKey peer_public_key.key else X25519::MontgomeryU.new(peer_public_key.to_s.b) end @key.diffie_hellman(pk).to_bytes end |
#public_key ⇒ PublicKey
Returns the corresponding public key.
59 60 61 |
# File 'lib/omq/blake3zmq/crypto.rb', line 59 def public_key PublicKey.new(@key.public_key.to_bytes) end |
#to_s ⇒ String
Returns the raw 32-byte secret key.
67 68 69 |
# File 'lib/omq/blake3zmq/crypto.rb', line 67 def to_s @key.to_bytes end |