Struct core_crypto::Keypair [−][src]
pub struct Keypair<Kp: KeyPairSchema>(pub Kp);
Expand description
It represents an asymmetric private/public encryption key.
Implementations
Generate a Keypair
random.
Example
use symbol_crypto_core::prelude::{Keypair, Sym}; let keypair = Keypair::<Sym>::random();
Construct a Keypair
from a hex encoded private key string.
Inputs
hex
: anS
representing the hex private key (String or &str).
Example
use symbol_crypto_core::prelude::{Keypair, Sym}; let private_key_hex: &str = "7D3E959EB0CD66CC1DB6E9C62CB81EC52747AB56FA740CF18AACB5003429AD2E"; let keypair = Keypair::<Sym>::from_hex_private_key(private_key_hex);
Returns
A Result
whose okay value is an Keypair
or whose error value
is an failure::Error
describing the error that occurred.
Construct a Keypair
PrivateKey
type.
Inputs
private_key
: representing thePrivateKey
type.
Example
use symbol_crypto_core::prelude::{Keypair, PrivateKey, Sym}; let private_key_hex: &str = "7D3E959EB0CD66CC1DB6E9C62CB81EC52747AB56FA740CF18AACB5003429AD2E"; let private_key = PrivateKey::from_str(private_key_hex).unwrap(); let keypair = Keypair::<Sym>::from_private_key(private_key);
Returns
A Keypair
Convert this keypair to bytes.
Returns
An array of bytes, [u8; KEYPAIR_LENGTH]
. The first
KEY_BYTES_SIZE
of bytes is the PrivateKey
, and the next
KEY_BYTES_SIZE
bytes is the PublicKey
.
Signs a data bytes with a Keypair
.
Inputs
data
: an&[u8]
representing the data to sign.
Example
use symbol_crypto_core::prelude::{Keypair, Sym}; let keypair = Keypair::<Sym>::random(); let data = b"8ce03cd60514233b86789729102ea09e867fc6d964dea8c2018ef7d0a2e0e24bf7e348e917116690b9"; let signature = keypair.sign(data.as_ref());
Returns
A Signature
the signature hash.
Encode a message text using the signer’s PrivateKey
of this Keypair and receiver’s
PublicKey
.
Inputs
-
receiver_pk
: The receiver’s public key. -
msg
: Message to encrypt.
Example
use symbol_crypto_core::prelude::{Keypair, Sym, PublicKey}; let message = b"Symbol is awesome from Rust!"; let encrypt_text = signer_kp.encrypt_message(receiver_pk.as_fixed_bytes(), message).unwrap();
Returns
A Result
whose okay value is an encrypt message Vec<u8>
or whose error value
is an failure::Error
describing the error that occurred.
Decrypt a message text using the receiver’s the PrivateKey of this Keypair and signer’s PublicKey.
Inputs
-
signer_pk
: The signer’s public key. -
enc_msg
: Message encrypted.
Example
use symbol_crypto_core::prelude::{Keypair, Sym, PublicKey}; let receiver_kp = Keypair::<Sym>::from_hex_private_key("A22A4BBF126A2D7D7ECE823174DFD184C5DE0FDE4CB2075D30CFA409F7EF8908").unwrap(); let signer_pk = PublicKey::from_str("3FD283D8543C12B81917C154CDF4EFD3D48E553E6D7BC77E29CB168138CED17D").unwrap(); let encrypt_text_vec = [ 125, 59, 126, 248, 124, 129, 157, 100, 111, 84, 49, 163, 111, 68, 22, 137, 75, 132, 135, 217, 251, 158, 115, 74, 226, 172, 200, 208, 33, 183, 110, 103, 107, 170, 52, 174, 192, 110, 164, 44, 77, 69, 203, 48, 43, 17, 206, 143, 154, 155, 231, 72, 28, 24, 20, 241, 234, 202, 184, 66, ]; let decrypted_text = receiver_kp.decrypt_message( signer_pk.as_fixed_bytes(), &encrypt_text_vec).unwrap();
Returns
A Result
whose okay value is an decrypted message Vec<u8>
or whose error value
is an failure::Error
describing the error that occurred.
Trait Implementations
Auto Trait Implementations
impl<Kp> RefUnwindSafe for Keypair<Kp> where
Kp: RefUnwindSafe,
impl<Kp> UnwindSafe for Keypair<Kp> where
Kp: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V