Class: RbNaCl::Boxes::Curve25519XSalsa20Poly1305::PrivateKey
- Inherits:
-
Object
- Object
- RbNaCl::Boxes::Curve25519XSalsa20Poly1305::PrivateKey
- Extended by:
- Sodium
- Includes:
- KeyComparator, Serializable
- Defined in:
- lib/rbnacl/boxes/curve25519xsalsa20poly1305/private_key.rb
Overview
RbNaCl::Box private key. Keep it safe
This class generates and stores NaCL private keys, as well as providing a reference to the public key associated with this private key, if that's provided.
Note that the documentation for NaCl refers to this as a secret key, but in this library its a private key, to avoid confusing the issue with the SecretBox, which does symmetric encryption.
Constant Summary collapse
- BYTES =
The size of the key, in bytes
Boxes::Curve25519XSalsa20Poly1305::PRIVATEKEYBYTES
Class Method Summary collapse
-
.generate ⇒ RbNaCl::PrivateKey
Generates a new keypair.
Instance Method Summary collapse
-
#initialize(private_key) ⇒ Object
constructor
Initializes a new PrivateKey for key operations.
-
#primitive ⇒ Symbol
The crypto primitive this PrivateKey is to be used for.
-
#public_key ⇒ PublicKey
the public key associated with this private key.
-
#to_bytes ⇒ String
The raw bytes of the key.
Methods included from Sodium
sodium_constant, sodium_function, sodium_primitive, sodium_type
Methods included from Serializable
Methods included from KeyComparator
Constructor Details
#initialize(private_key) ⇒ Object
Initializes a new PrivateKey for key operations.
Takes the (optionally encoded) private key bytes. This class can then be used for various key operations, including deriving the corresponding PublicKey
43 44 45 |
# File 'lib/rbnacl/boxes/curve25519xsalsa20poly1305/private_key.rb', line 43 def initialize(private_key) @private_key = Util.check_string(private_key, BYTES, "Private key") end |
Class Method Details
.generate ⇒ RbNaCl::PrivateKey
Generates a new keypair
52 53 54 55 56 57 |
# File 'lib/rbnacl/boxes/curve25519xsalsa20poly1305/private_key.rb', line 52 def self.generate pk = Util.zeros(Boxes::Curve25519XSalsa20Poly1305::PUBLICKEYBYTES) sk = Util.zeros(Boxes::Curve25519XSalsa20Poly1305::PRIVATEKEYBYTES) box_curve25519xsalsa20poly1305_keypair(pk, sk) || fail(CryptoError, "Failed to generate a key pair") new(sk) end |
Instance Method Details
#primitive ⇒ Symbol
The crypto primitive this PrivateKey is to be used for.
76 77 78 |
# File 'lib/rbnacl/boxes/curve25519xsalsa20poly1305/private_key.rb', line 76 def primitive self.class.primitive end |
#public_key ⇒ PublicKey
the public key associated with this private key
69 70 71 |
# File 'lib/rbnacl/boxes/curve25519xsalsa20poly1305/private_key.rb', line 69 def public_key @public_key ||= PublicKey.new GroupElements::Curve25519.base.mult(to_bytes) end |
#to_bytes ⇒ String
The raw bytes of the key
62 63 64 |
# File 'lib/rbnacl/boxes/curve25519xsalsa20poly1305/private_key.rb', line 62 def to_bytes @private_key end |