IPWorks Encrypt 2020 Delphi Edition

Questions / Feedback?

ECC Component

Properties   Methods   Events   Configuration Settings   Errors  

The ECC (Elliptic Curve Cryptography) component implements ECDSA, EdDSA, ECDH, and ECIES operations.

Syntax

TipcECC

Remarks

The ECC (Elliptic Curve Cryptography) component implements ECDSA (Elliptic Curve Digital Signature Algorithm), EdDSA (Edwards-curve Digital Signature Algorithm), and ECDH (Elliptic Curve Diffie Hellman), and ECIES (Elliptic Curve Integrated Encryption Scheme) operations. The component supports the following common operations:

  • CreateKey allows key creation for secp256r1, secp384r1, secp521r1, x25519, x448, ed25519, and ed448 keys.
  • ComputeSecret computes a shared secret between two parties using a public and private key (ECDH).
  • Sign and Verify provides a way to digitally sign data and verify signatures (ECDSA and EdDSA).
  • Encrypt and Decrypt encrypt and decrypt data using a public and private key (ECIES).

The component is very flexible and offers many properties and configuration settings to configure the component. The sections below detail the use of the component for each of the major operations listed above.

Key Creation and Management

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"

Compute Secret (ECDH)

This method computes a shared secret using Elliptic Curve Diffie Hellman (ECDH).

When this method is called the component will use the public key specified by PublicKey and the private key specified by Key to compute a shared secret, or secret agreement. The ComputeSecretKDF property specifies the Hash or HMAC algorithm that is applied to the raw secret. The resulting value is held by SharedSecret. The following properties are applicable when calling this method:

See ComputeSecretKDF for details on advanced settings that may be applicable for the chosen algorithm.

Keys created with the ed25519 and ed448 algorithms are not supported when calling this method.

Compute Secret Example


//Create a key for Party 1
Ecc ecc1 = new Ecc();
ecc1.CreateKey("x25519");
string ecc1_priv = ecc1.Key.PrivateKey;
string ecc1_pub = ecc1.Key.PublicKey;

//Create a key for Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("x25519");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Note: the public keys must be exchanged between parties by some mechanism

//Create the shared secret on Party 1
ecc1.Reset();
ecc1.Key.PrivateKey = ecc1_priv; //Private key of this party
ecc1.RecipientKey.PublicKey = ecc2_pub; //Public key of other party
ecc1.UseHex = true; //Hex encodes the shared secret bytes for easier display/storage
ecc1.ComputeSecret();

Console.WriteLine(ecc1.SharedSecret);

//Create the shared secret on Party 2
ecc2.Reset();
ecc2.Key.PrivateKey = ecc2_priv; //Private key of this party
ecc2.RecipientKey.PublicKey = ecc1_pub; //Public key of other party
ecc2.UseHex = true; //Hex encodes the shared secret bytes for easier display/storage
ecc2.ComputeSecret();

Console.WriteLine(ecc2.SharedSecret); //This will match the shared secret created by ecc1.

Signing (ECDSA and EdDSA)

Sign will create a hash signature using ECDSA or EdDSA. The component will use the key specified by Key to has the input data and sign the resulting hash.

Key must contain a private key created with a valid ECDSA or EdDSA algorithm. Algorithm is used to determine the eligibility of the key for this operation. Supported algorithms for signing are:

  • secp256r1
  • secp384r1
  • secp521r1
  • ed25519
  • ed448

See CreateKey for details about key creation and algorithms.

When this method is called data will be read from the InputFile or InputMessage.

The hash to be signed will be computed using the specified HashAlgorithm. The computed hash is stored in the HashValue property. The signed hash is stored in the HashSignature property.

To sign as hash without first computing it set HashValue to a previously computed hash for the input data. Note: HashValue is not applicable when signing with a PureEdDSA algorithm such as "ed25519" or "ed448".

The Progress event will fire with updates for the hash computation progress only. The hash signature creation process is quick and does not require progress updates.

After calling Sign the public key must be sent to the recipient along with HashSignature and original input data so the other party may perform signature verification.

The following properties are applicable when calling this method:

The following properties are populated after calling this method:

EdDSA Notes

When the Algorithm is ed25519 or ed448 the following additional parameters are applicable:

EdDSA keys can be used with a PureEdDSA algorithm (ed25519/ed448) or as HashEdDSA (ed25519ph, ed448ph) algorithm. This is controlled by the HashEdDSA property. By default the component uses the PureEdDSA algorithm.

The PureEdDSA algorithm requires two passes over the input data but provides collision resilience. The collision resilience of PureEdDSA means even if it is feasible to compute collisions for the hash function, the algorithm is still secure. When using PureEdDSA HashValue is not applicable.

When using a HashEdDSA algorithm the input is pre-hashed and supports a single pass over the data during the signing operation. To enable HashEdDSA set HashEdDSA to True.

To specify context data when using ed25519 or ed448 set EdDSAContext.

Sign And Verify Example (ECDSA)


//Create an ECDSA key on Party 1
Ecc ecc1 = new Ecc();
ecc1.CreateKey("secp256r1");
string ecc1_priv = ecc1.Key.PrivateKey;
string ecc1_pub = ecc1.Key.PublicKey;

//Sign the data on Party 1
string originalData = "hello ecc";

ecc1.Reset();
ecc1.Key.PrivateKey = ecc1_priv;
ecc1.InputMessage = originalData;
ecc1.UseHex = true; //Hex encode the hash signature for ease of use.
ecc1.Sign();

string hashSignature = ecc1.HashSignature;

//Transmit the hash signature, public key, and original data to part 2

//Verify the data on Party 2
Ecc ecc2 = new Ecc();
ecc2.SignerKey.PublicKey = ecc1_pub;
ecc2.InputMessage = originalData;
ecc2.HashSignature = hashSignature;
ecc2.UseHex = true; //Decode the hex encoded hash signature

bool isVerified = ecc2.VerifySignature();

Sign And Verify Example (EdDSA - PureEdDSA)


//Create an EdDSA key on Party 1
Ecc ecc1 = new Ecc();
ecc1.CreateKey("ed25519");
string ecc1_priv = ecc1.Key.PrivateKey;
string ecc1_pub = ecc1.Key.PublicKey;

//Sign the data on Party 1
string originalData = "hello ecc";

ecc1.Reset();
ecc1.Key.PrivateKey = ecc1_priv;
ecc1.InputMessage = originalData;
ecc1.UseHex = true; //Hex encode the hash signature for ease of use.
ecc1.Sign();

string hashSignature = ecc1.HashSignature;

//Transmit the hash signature, public key, and original data to part 2

//Verify the data on Party 2
Ecc ecc2 = new Ecc();
ecc2.SignerKey.PublicKey = ecc1_pub;
ecc2.InputMessage = originalData;
ecc2.HashSignature = hashSignature;
ecc2.UseHex = true; //Decode the hex encoded hash signature

bool isVerified = ecc2.VerifySignature();

Sign And Verify Example (EdDSA - HashEdDSA)


//Create an EdDSA key on Party 1
Ecc ecc1 = new Ecc();
ecc1.CreateKey("ed25519");
string ecc1_priv = ecc1.Key.PrivateKey;
string ecc1_pub = ecc1.Key.PublicKey;

//Sign the data on Party 1
string originalData = "hello ecc";

ecc1.Reset();
ecc1.Key.PrivateKey = ecc1_priv;
ecc1.InputMessage = originalData;
ecc1.UseHex = true; //Hex encode the hash signature for ease of use.
ecc1.HashEdDSA = true; //Use "ed25519ph"
ecc1.Sign();

string hashSignature = ecc1.HashSignature;

//Transmit the hash signature, public key, and original data to part 2

//Verify the data on Party 2
Ecc ecc2 = new Ecc();
ecc2.SignerKey.PublicKey = ecc1_pub;
ecc2.InputMessage = originalData;
ecc2.HashSignature = hashSignature;
ecc2.HashEdDSA = true;
ecc2.UseHex = true; //Decode the hex encoded hash signature

bool isVerified = ecc2.VerifySignature();

Verifying (ECDSA and EdDSA)

VerifySignature will verify a hash signature and return True if successful or False otherwise.

Before calling this method specify the input file by setting InputFile or InputMessage.

A public key and the hash signature are required to perform the signature verification. Specify the public key in SignerKey. Specify the hash signature in HashSignature.

When this method is called the component will compute the hash for the specified file and populate HashValue. It will verify the signature using the specified SignerKey and HashSignature.

To verify the hash signature without first computing the hash simply specify HashValue before calling this method. Note: HashValue is not applicable when the message was signed with a PureEdDSA algorithm such as ed25519 or ed448.

The Progress event will fire with updates for the hash computation progress only. The hash signature verification process is quick and does not require progress updates.

The following properties are applicable when calling this method:

Sign And Verify Example (ECDSA)


//Create an ECDSA key on Party 1
Ecc ecc1 = new Ecc();
ecc1.CreateKey("secp256r1");
string ecc1_priv = ecc1.Key.PrivateKey;
string ecc1_pub = ecc1.Key.PublicKey;

//Sign the data on Party 1
string originalData = "hello ecc";

ecc1.Reset();
ecc1.Key.PrivateKey = ecc1_priv;
ecc1.InputMessage = originalData;
ecc1.UseHex = true; //Hex encode the hash signature for ease of use.
ecc1.Sign();

string hashSignature = ecc1.HashSignature;

//Transmit the hash signature, public key, and original data to part 2

//Verify the data on Party 2
Ecc ecc2 = new Ecc();
ecc2.SignerKey.PublicKey = ecc1_pub;
ecc2.InputMessage = originalData;
ecc2.HashSignature = hashSignature;
ecc2.UseHex = true; //Decode the hex encoded hash signature

bool isVerified = ecc2.VerifySignature();

Sign And Verify Example (EdDSA - PureEdDSA)


//Create an EdDSA key on Party 1
Ecc ecc1 = new Ecc();
ecc1.CreateKey("ed25519");
string ecc1_priv = ecc1.Key.PrivateKey;
string ecc1_pub = ecc1.Key.PublicKey;

//Sign the data on Party 1
string originalData = "hello ecc";

ecc1.Reset();
ecc1.Key.PrivateKey = ecc1_priv;
ecc1.InputMessage = originalData;
ecc1.UseHex = true; //Hex encode the hash signature for ease of use.
ecc1.Sign();

string hashSignature = ecc1.HashSignature;

//Transmit the hash signature, public key, and original data to part 2

//Verify the data on Party 2
Ecc ecc2 = new Ecc();
ecc2.SignerKey.PublicKey = ecc1_pub;
ecc2.InputMessage = originalData;
ecc2.HashSignature = hashSignature;
ecc2.UseHex = true; //Decode the hex encoded hash signature

bool isVerified = ecc2.VerifySignature();

Sign And Verify Example (EdDSA - HashEdDSA)


//Create an EdDSA key on Party 1
Ecc ecc1 = new Ecc();
ecc1.CreateKey("ed25519");
string ecc1_priv = ecc1.Key.PrivateKey;
string ecc1_pub = ecc1.Key.PublicKey;

//Sign the data on Party 1
string originalData = "hello ecc";

ecc1.Reset();
ecc1.Key.PrivateKey = ecc1_priv;
ecc1.InputMessage = originalData;
ecc1.UseHex = true; //Hex encode the hash signature for ease of use.
ecc1.HashEdDSA = true; //Use "ed25519ph"
ecc1.Sign();

string hashSignature = ecc1.HashSignature;

//Transmit the hash signature, public key, and original data to part 2

//Verify the data on Party 2
Ecc ecc2 = new Ecc();
ecc2.SignerKey.PublicKey = ecc1_pub;
ecc2.InputMessage = originalData;
ecc2.HashSignature = hashSignature;
ecc2.HashEdDSA = true;
ecc2.UseHex = true; //Decode the hex encoded hash signature

bool isVerified = ecc2.VerifySignature();

Encrypting (ECIES)

Encrypt encrypts the specified data with the ECDSA public key specified in RecipientKey.

Encryption is performed using ECIES which requires an ECDSA key. RecipientKey must contain an ECDSA key. Algorithm is used to determine the eligibility of the key for this operation. Supported algorithms for encryption are:

  • secp256r1
  • secp384r2
  • secp521r1

See CreateKey for details about key creation and algorithms.

When this method is called the component will encrypt the specified data using ECIES and the encrypted data will be output. To hex encode the output set UseHex to True.

The following properties are applicable when calling this method:

Input and Output Properties

The component will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

When using streams you may need to additionally set CloseInputStreamAfterProcessing or CloseOutputStreamAfterProcessing.

Encrypt and Decrypt Example


//Create an ECDSA key on Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("secp256r1");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Transmit public key to Party 1

//Encrypt the message on Party 1 using public key from Party 2
Ecc ecc1 = new Ecc();
ecc1.InputMessage = "hello ecc";
ecc1.RecipientKey.PublicKey = ecc2_pub;
ecc1.UseHex = true;
ecc1.Encrypt();

string encryptedMessage = ecc1.OutputMessage;

//Transmit the encrypted message to Party 2

//Decrypt the message using the private key for Party 2
ecc2.Key.PrivateKey = ecc2_priv;
ecc2.InputMessage = encryptedMessage;
ecc2.UseHex = true;
ecc2.Decrypt();

Console.WriteLine(ecc2.OutputMessage);

Encrypt and Decrypt Example (AES with IV)


//Create an ECDSA key on Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("secp256r1");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Transmit public key to Party 1

//Encrypt the message on Party 1 using public key from Party 2
Ecc ecc1 = new Ecc();

//Use an IV (16 bytes for AES) - In a real environment this should be random
byte[] IV = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

ecc1.EncryptionAlgorithm = EccEncryptionAlgorithms.iesAES;
ecc1.IVB = IV;

ecc1.InputMessage = "hello ecc";
ecc1.RecipientKey.PublicKey = ecc2_pub;
ecc1.UseHex = true;
ecc1.Encrypt();

string encryptedMessage = ecc1.OutputMessage;

//Transmit the encrypted message and the IV to Party 2

//Decrypt the message using the private key for Party 2 and the IV
ecc2.EncryptionAlgorithm = EccEncryptionAlgorithms.iesAES;
ecc2.IVB = IV;
ecc2.Key.PrivateKey = ecc2_priv;
ecc2.InputMessage = encryptedMessage;
ecc2.UseHex = true;
ecc2.Decrypt();

Console.WriteLine(ecc2.OutputMessage);

Encrypt and Decrypt Example (XOR Encryption Algorithm)


//Create an ECDSA key on Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("secp256r1");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Transmit public key to Party 1

//Encrypt the message on Party 1 using public key from Party 2
Ecc ecc1 = new Ecc();
ecc1.EncryptionAlgorithm = EccEncryptionAlgorithms.iesXOR;
ecc1.InputMessage = "hello ecc";
ecc1.RecipientKey.PublicKey = ecc2_pub;
ecc1.UseHex = true;
ecc1.Encrypt();

string encryptedMessage = ecc1.OutputMessage;

//Transmit the encrypted message to Party 2

//Decrypt the message using the private key for Party 2
ecc2.EncryptionAlgorithm = EccEncryptionAlgorithms.iesXOR;
ecc2.Key.PrivateKey = ecc2_priv;
ecc2.InputMessage = encryptedMessage;
ecc2.UseHex = true;
ecc2.Decrypt();

Console.WriteLine(ecc2.OutputMessage);

Encrypt and Decrypt Example (KDF Options)


//Create an ECDSA key on Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("secp256r1");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Transmit public key to Party 1

//Encrypt the message on Party 1 using public key from Party 2
Ecc ecc1 = new Ecc();

ecc1.KDF = "KDF1"; //Use KDF1
ecc1.KDFHashAlgorithm = EccKDFHashAlgorithms.iesSHA1;
ecc1.Config("KDFOptionalInfo=202122232425262728292a2b2c2d2e2f"); //Hex encoded string

ecc1.InputMessage = "hello ecc";
ecc1.RecipientKey.PublicKey = ecc2_pub;
ecc1.UseHex = true;
ecc1.Encrypt();

string encryptedMessage = ecc1.OutputMessage;

//Transmit the encrypted message to Party 2

//Decrypt the message using the private key for Party 2
ecc2.KDF = "KDF1";
ecc2.KDFHashAlgorithm = EccKDFHashAlgorithms.iesSHA1;
ecc2.Config("KDFOptionalInfo=202122232425262728292a2b2c2d2e2f");

ecc2.Key.PrivateKey = ecc2_priv;
ecc2.InputMessage = encryptedMessage;
ecc2.UseHex = true;
ecc2.Decrypt();

Console.WriteLine(ecc2.OutputMessage);

Decrypting (ECIES)

Decrypt decrypts the specified data with the ECDSA private key specified in Key.

Decryption is performed using ECIES which requires an ECDSA key. Key must contain an ECDSA key. Algorithm is used to determine the eligibility of the key for this operation. Supported algorithms for encryption are:

  • secp256r1
  • secp384r2
  • secp521r1

See CreateKey for details about key creation and algorithms.

When this method is called the component will decrypt the specified data using ECIES and the decrypted data will be output. If the input data was originally hex encoded, set UseHex to True.

The following properties are applicable when calling this method:

Input and Output Properties

The component will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

When using streams you may need to additionally set CloseInputStreamAfterProcessing or CloseOutputStreamAfterProcessing.

Encrypt and Decrypt Example


//Create an ECDSA key on Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("secp256r1");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Transmit public key to Party 1

//Encrypt the message on Party 1 using public key from Party 2
Ecc ecc1 = new Ecc();
ecc1.InputMessage = "hello ecc";
ecc1.RecipientKey.PublicKey = ecc2_pub;
ecc1.UseHex = true;
ecc1.Encrypt();

string encryptedMessage = ecc1.OutputMessage;

//Transmit the encrypted message to Party 2

//Decrypt the message using the private key for Party 2
ecc2.Key.PrivateKey = ecc2_priv;
ecc2.InputMessage = encryptedMessage;
ecc2.UseHex = true;
ecc2.Decrypt();

Console.WriteLine(ecc2.OutputMessage);

Encrypt and Decrypt Example (AES with IV)


//Create an ECDSA key on Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("secp256r1");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Transmit public key to Party 1

//Encrypt the message on Party 1 using public key from Party 2
Ecc ecc1 = new Ecc();

//Use an IV (16 bytes for AES) - In a real environment this should be random
byte[] IV = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

ecc1.EncryptionAlgorithm = EccEncryptionAlgorithms.iesAES;
ecc1.IVB = IV;

ecc1.InputMessage = "hello ecc";
ecc1.RecipientKey.PublicKey = ecc2_pub;
ecc1.UseHex = true;
ecc1.Encrypt();

string encryptedMessage = ecc1.OutputMessage;

//Transmit the encrypted message and the IV to Party 2

//Decrypt the message using the private key for Party 2 and the IV
ecc2.EncryptionAlgorithm = EccEncryptionAlgorithms.iesAES;
ecc2.IVB = IV;
ecc2.Key.PrivateKey = ecc2_priv;
ecc2.InputMessage = encryptedMessage;
ecc2.UseHex = true;
ecc2.Decrypt();

Console.WriteLine(ecc2.OutputMessage);

Encrypt and Decrypt Example (XOR Encryption Algorithm)


//Create an ECDSA key on Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("secp256r1");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Transmit public key to Party 1

//Encrypt the message on Party 1 using public key from Party 2
Ecc ecc1 = new Ecc();
ecc1.EncryptionAlgorithm = EccEncryptionAlgorithms.iesXOR;
ecc1.InputMessage = "hello ecc";
ecc1.RecipientKey.PublicKey = ecc2_pub;
ecc1.UseHex = true;
ecc1.Encrypt();

string encryptedMessage = ecc1.OutputMessage;

//Transmit the encrypted message to Party 2

//Decrypt the message using the private key for Party 2
ecc2.EncryptionAlgorithm = EccEncryptionAlgorithms.iesXOR;
ecc2.Key.PrivateKey = ecc2_priv;
ecc2.InputMessage = encryptedMessage;
ecc2.UseHex = true;
ecc2.Decrypt();

Console.WriteLine(ecc2.OutputMessage);

Encrypt and Decrypt Example (KDF Options)


//Create an ECDSA key on Party 2
Ecc ecc2 = new Ecc();
ecc2.CreateKey("secp256r1");
string ecc2_priv = ecc2.Key.PrivateKey;
string ecc2_pub = ecc2.Key.PublicKey;

//Transmit public key to Party 1

//Encrypt the message on Party 1 using public key from Party 2
Ecc ecc1 = new Ecc();

ecc1.KDF = "KDF1"; //Use KDF1
ecc1.KDFHashAlgorithm = EccKDFHashAlgorithms.iesSHA1;
ecc1.Config("KDFOptionalInfo=202122232425262728292a2b2c2d2e2f"); //Hex encoded string

ecc1.InputMessage = "hello ecc";
ecc1.RecipientKey.PublicKey = ecc2_pub;
ecc1.UseHex = true;
ecc1.Encrypt();

string encryptedMessage = ecc1.OutputMessage;

//Transmit the encrypted message to Party 2

//Decrypt the message using the private key for Party 2
ecc2.KDF = "KDF1";
ecc2.KDFHashAlgorithm = EccKDFHashAlgorithms.iesSHA1;
ecc2.Config("KDFOptionalInfo=202122232425262728292a2b2c2d2e2f");

ecc2.Key.PrivateKey = ecc2_priv;
ecc2.InputMessage = encryptedMessage;
ecc2.UseHex = true;
ecc2.Decrypt();

Console.WriteLine(ecc2.OutputMessage);

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

ComputeSecretKDFThe key derivation function.
EncryptionAlgorithmThe encryption algorithm to use.
HashAlgorithmThe hash algorithm used for hash computation.
HashEdDSAWhether to use HashEdDSA when signing with an ed25519 or ed448 key.
HashSignatureThe hash signature.
HashValueThe hash value of the data.
HMACAlgorithmThe HMAC algorithm to use during encryption.
InputFileThe file to process.
InputMessageThe message to process.
IVThe initialization vector (IV) used when encrypting.
KDFThe key derivation function used during encryption and decryption.
KDFHashAlgorithmThe KDF hash algorithm to use when encrypting and decrypting.
KeyThe ECC key.
OutputFileThe output file when encrypting or decrypting.
OutputMessageThe output message when encrypting or decrypting.
OverwriteIndicates whether or not the component should overwrite files.
RecipientKeyThe public key used to compute the shared secret.
SharedSecretThe computed shared secret.
SignerKeyThe public key used to verify the signature.
UseHexWhether binary values are hex encoded.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

ComputeSecretComputes a shared secret.
ConfigSets or retrieves a configuration setting.
CreateKeyCreates a new key.
DecryptDecrypted the specified data.
EncryptEncrypts the specified data.
ResetResets the component.
SetInputStreamSets the stream from which the component will read data to encrypt or decrypt.
SetOutputStreamSets the stream to which the component will write encrypted or decrypted data.
SignCreates a hash signature using ECDSA or EdDSA.
VerifySignatureVerifies the signature for the specified data.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ErrorInformation about errors during data delivery.
ProgressFired as progress is made.

Configuration Settings


The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.

AppendSecretAn optional string to append to the secret agreement.
CNGECDHKeyThe CNG ECDH key.
CNGECDSAKeyThe CNG ECDSA key.
ConcatAlgorithmIdSpecifies the AlgorithmId subfield of the OtherInfo field.
ConcatHashAlgorithmThe hash algorithm to use when ComputeSecretKDF is Concat.
ConcatPartyUInfoSpecifies the PartyUInfo subfield of the OtherInfo field.
ConcatPartyVInfoSpecifies the PartyVInfo subfield of the OtherInfo field.
ConcatSuppPrivInfoSpecifies the SuppPrivInfo subfield of the OtherInfo field.
ConcatSuppPubInfoSpecifies the SuppPubInfo subfield of the OtherInfo field.
ECDSASignatureFormatThe format of the HashSignature when using ECDSA keys.
EdDSAContextA hex encoded string holding the bytes of the context when signing or verifying with ed25519ctx.
EncryptionKeySizeThe encryption key size.
HMACKeyA key to use when generating a Hash-based Message Authentication Code (HMAC).
HMACKeySizeSpecifies the HMAC key size to be used during encryption.
HMACOptionalInfoOptional data to be used during encryption and decryption during the HMAC step.
KDFOptionalInfoOptional data to be used during encryption and decryption during the key derivation step.
PrependSecretAn optional string to prepend to the secret agreement.
StrictKeyValidationWhether to validate provided public keys based on private keys.
TLSLabelThe TLS PRF label.
TLSSeedThe TLS PRF Seed.
BuildInfoInformation about the product's build.
CodePageThe system code page used for Unicode to Multibyte translations.
LicenseInfoInformation about the current license.
UseInternalSecurityAPITells the component whether or not to use the system security libraries or an internal implementation.

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