pub struct PrivateKey(/* private fields */);
Expand description
This is a private key which is to be kept secret and is used to prove identity
Implementations§
source§impl PrivateKey
impl PrivateKey
sourcepub fn export_encrypted(
&self,
password: &str,
log2_rounds: u8,
) -> Result<EncryptedPrivateKey, Error>
pub fn export_encrypted( &self, password: &str, log2_rounds: u8, ) -> Result<EncryptedPrivateKey, Error>
Export in a (non-portable) encrypted form. This does not downgrade
the security of the key, but you are responsible to keep it encrypted.
You should not attempt to decrypt it, only use import_encrypted()
on
it, or something similar in another library/client which also respects key
security.
This currently exports into EncryptedPrivateKey version 2.
We recommend you zeroize() the password you pass in after you are done with it.
sourcepub fn import_encrypted(
encrypted: &EncryptedPrivateKey,
password: &str,
) -> Result<PrivateKey, Error>
pub fn import_encrypted( encrypted: &EncryptedPrivateKey, password: &str, ) -> Result<PrivateKey, Error>
Import an encrypted private key which was exported with export_encrypted()
.
We recommend you zeroize() the password you pass in after you are done with it.
This is backwards-compatible with keys that were exported with older code.
source§impl PrivateKey
impl PrivateKey
Get the shared secret
sourcepub fn encrypt(
&self,
other: &PublicKey,
plaintext: &str,
algo: ContentEncryptionAlgorithm,
) -> Result<String, Error>
pub fn encrypt( &self, other: &PublicKey, plaintext: &str, algo: ContentEncryptionAlgorithm, ) -> Result<String, Error>
Encrypt
sourcepub fn detect_encryption_algorithm(
ciphertext: &str,
) -> ContentEncryptionAlgorithm
pub fn detect_encryption_algorithm( ciphertext: &str, ) -> ContentEncryptionAlgorithm
Detect encryption algorithm of ciphertext
sourcepub fn decrypt(
&self,
other: &PublicKey,
ciphertext: &str,
) -> Result<String, Error>
pub fn decrypt( &self, other: &PublicKey, ciphertext: &str, ) -> Result<String, Error>
Decrypt (detects encryption version)
source§impl PrivateKey
impl PrivateKey
sourcepub fn new() -> PrivateKey
pub fn new() -> PrivateKey
Generate a new PrivateKey
(which can be used to get the PublicKey
)
sourcepub fn generate() -> PrivateKey
pub fn generate() -> PrivateKey
Generate a new PrivateKey
(which can be used to get the PublicKey
)
sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Get the PublicKey matching this PrivateKey
sourcepub fn key_security(&self) -> KeySecurity
pub fn key_security(&self) -> KeySecurity
Get the security level of the private key
sourcepub fn as_hex_string(&mut self) -> String
pub fn as_hex_string(&mut self) -> String
Render into a hexadecimal string
WARNING: This weakens the security of your key. Your key will be marked
with KeySecurity::Weak
if you execute this.
sourcepub fn try_from_hex_string(v: &str) -> Result<PrivateKey, Error>
pub fn try_from_hex_string(v: &str) -> Result<PrivateKey, Error>
Create from a hexadecimal string
This creates a key with KeySecurity::Weak
. Use generate()
or
import_encrypted()
for KeySecurity::Medium
sourcepub fn as_bech32_string(&mut self) -> String
pub fn as_bech32_string(&mut self) -> String
Export as a bech32 encoded string
WARNING: This weakens the security of your key. Your key will be marked
with KeySecurity::Weak
if you execute this.
sourcepub fn try_from_bech32_string(s: &str) -> Result<PrivateKey, Error>
pub fn try_from_bech32_string(s: &str) -> Result<PrivateKey, Error>
Import from a bech32 encoded string
This creates a key with KeySecurity::Weak
. Use generate()
or
import_encrypted()
for KeySecurity::Medium
sourcepub fn as_secret_key(&self) -> SecretKey
pub fn as_secret_key(&self) -> SecretKey
As a secp256k1::SecretKey
Trait Implementations§
source§impl Debug for PrivateKey
impl Debug for PrivateKey
source§impl Default for PrivateKey
impl Default for PrivateKey
source§impl Drop for PrivateKey
impl Drop for PrivateKey
source§impl Signer for PrivateKey
impl Signer for PrivateKey
source§fn decrypt(&self, other: &PublicKey, ciphertext: &str) -> Result<String, Error>
fn decrypt(&self, other: &PublicKey, ciphertext: &str) -> Result<String, Error>
Decrypt NIP-44
source§fn nip44_conversation_key(&self, other: &PublicKey) -> Result<[u8; 32], Error>
fn nip44_conversation_key(&self, other: &PublicKey) -> Result<[u8; 32], Error>
Get NIP-44 conversation key