KeyPair

TonSdk.Core.Crypto

KeyPair is a class, that is used to work with keypairs (private and public keys).

KeyPair can be created via using Mnemonic class, for example:

// with creating new mnemonic instance
Mnemonic mnemonic = new Mnemonic();
KeyPair keys = mnemonic.Keys;

// or directly
byte[] seed = /* 32 bytes of seed */;
KeyPair keys1 = Mnemonic.GenerateKeyPair(seed);

Each KeyPair class contains PrivateKey and PublicKey fields:

Mnemonic mnemonic = new Mnemonic();
KeyPair keys = mnemonic.Keys;

byte[] privateKey = keys.PrivateKey;
byte[] publicKey = keys.PublicKey;

Each key is a 32 byte array.

With using KeyPair.Sign() you can sign any data with specified PrivateKey:

Mnemonic mnemonic = new Mnemonic();
KeyPair keys = mnemonic.Keys;
Cell data = /* your data in cell instance */

byte[] signedBytes = KeyPair.Sign(data, keys.PrivateKey)

Last updated