IPWorks Encrypt 2020 Python Edition

Questions / Feedback?

create_key Method

Creates a new key.

Syntax

def create_key(key_algorithm: str) -> None: ...

Remarks

on_create_key creates a new public and private key.

When this method is called key is populated with the generated key. The key_public_key and key_private_key property hold the PEM formatted public and private key for ease of use. This is helpful for storing or transporting keys more easily.

The KeyAlgorithm parameter specifies the algorithm for which the key is intended to be used. Possible values are:

KeyAlgorithmSupported Operations
secp256r1ECDH/ECIES/ECDSA (compute_secret, encrypt, decrypt, sign, and verify_signature)
secp384r1ECDH/ECIES/ECDSA (compute_secret, encrypt, decrypt, sign, and verify_signature)
secp521r1ECDH/ECIES/ECDSA (compute_secret, encrypt, decrypt, sign, and verify_signature)
x25519ECDH (compute_secret)
x448ECDH (compute_secret)
ed25519EdDSA (sign and verify_signature)
ed448EdDSA (sign and verify_signature)
eaSecp160k1ECDH/ECIES/ECDSA (compute_secret, encrypt, decrypt, sign, and verify_signature)
eaSecp192k1ECDH/ECIES/ECDSA (compute_secret, encrypt, decrypt, sign, and verify_signature)
eaSecp224k1ECDH/ECIES/ECDSA (compute_secret, encrypt, decrypt, sign, and verify_signature)
eaSecp256k1ECDH/ECIES/ECDSA (compute_secret, encrypt, decrypt, sign, and verify_signature)

NIST Curve Notes

Keys for use with the secp256r1, secp384r1, and secp521r1 curves are made up of a number of individual parameters.

The public key consists of the following parameters:

The private key consists of one value:

Curve25519 and Curve448 Notes

Keys for use with Curve25519 or Curve448 are made up of a private key and public key field.

key_x_pk holds the public key.

key_x_sk holds the private key.

Create Key Example (secp256r1 - PEM)


//Create a key using secp256r1
Ecc ecc = new Ecc();
ecc.CreateKey("secp256r1");

Console.WriteLine(ecc.Key.Algorithm); //outputs enum value "eaSecp256r1"
string privKey = ecc.Key.PrivateKey; //PEM formatted key
string pubKey = ecc.Key.PublicKey; //PEM formatted key

//Load the saved key
ecc.Reset();
ecc.Key.PublicKey = pubKey;
ecc.Key.PrivateKey = privKey;
Console.WriteLine(ecc.Key.Algorithm); //outputs enum value "eaSecp256r1"

Create Key Example (secp256r1 - Raw Key Params)


//Create a key using secp256r1 and store/load the key using the individual params
Ecc ecc = new Ecc();
ecc.CreateKey("secp256r1");

Console.WriteLine(ecc.Key.Algorithm); //outputs enum value "eaSecp256r1"
byte[] K = ecc.Key.KB; //Private key param
byte[] Rx = ecc.Key.RxB; //Public key param
byte[] Ry = ecc.Key.RyB; //Public key param


//Load the saved key
ecc.Reset();
ecc.Key.Algorithm = ECAlgorithms.eaSecp256r1; //This MUST be set manually when using key params directly
ecc.Key.KB = K;
ecc.Key.RxB = Rx;
ecc.Key.RyB = Ry;

Console.WriteLine(ecc.Key.Algorithm); //outputs enum value "eaSecp256r1"

Create Key Example (ed25519 - PEM)


//Create a key using ed25519
Ecc ecc = new Ecc();
ecc.CreateKey("ed25519");

Console.WriteLine(ecc.Key.Algorithm); //outputs enum value "eaEd25519"
string privKey = ecc.Key.PrivateKey; //PEM formatted key
string pubKey = ecc.Key.PublicKey; //PEM formatted key

//Load the saved key
ecc.Reset();
ecc.Key.PublicKey = pubKey;
ecc.Key.PrivateKey = privKey;
Console.WriteLine(ecc.Key.Algorithm); //outputs enum value "eaEd25519"

Create Key Example (ed25519 - Raw Key Params)


//Create a key using ed25519 and store/load the key using the individual params
Ecc ecc = new Ecc();
ecc.CreateKey("ed25519");

Console.WriteLine(ecc.Key.Algorithm); //outputs enum value "eaEd25519"
byte[] XPk = ecc.Key.XPkB; //Public key data
byte[] XSk = ecc.Key.XSkB; //Secret key data

//Load the saved key
ecc.Reset();
ecc.Key.Algorithm = ECAlgorithms.eaEd25519;  //This MUST be set manually when using key params directly
ecc.Key.XPkB = XPk;
ecc.Key.XSkB = XSk;
Console.WriteLine(ecc.Key.Algorithm); //outputs enum value "eaEd25519"

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Encrypt 2020 Python Edition - Version 20.0 [Build 8155]