IPWorks Encrypt 2020 Delphi Edition

Questions / Feedback?

CreateKey Method

Creates a new key.

procedure CreateKey(KeyAlgorithm: String);

Remarks

CreateKey creates a new public and private key.

When this method is called Key is populated with the generated key. The PublicKey and PrivateKey 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 (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature)
secp384r1ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature)
secp521r1ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature)
x25519ECDH (ComputeSecret)
x448ECDH (ComputeSecret)
ed25519EdDSA (Sign and VerifySignature)
ed448EdDSA (Sign and VerifySignature)
eaSecp160k1ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature)
eaSecp192k1ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature)
eaSecp224k1ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature)
eaSecp256k1ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature)

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.

XPk holds the public key.

XSk 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 Delphi Edition - Version 20.0 [Build 8155]