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:
KeyAlgorithm | Supported Operations |
secp256r1 | ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature) |
secp384r1 | ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature) |
secp521r1 | ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature) |
x25519 | ECDH (ComputeSecret) |
x448 | ECDH (ComputeSecret) |
ed25519 | EdDSA (Sign and VerifySignature) |
ed448 | EdDSA (Sign and VerifySignature) |
eaSecp160k1 | ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature) |
eaSecp192k1 | ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature) |
eaSecp224k1 | ECDH/ECIES/ECDSA (ComputeSecret, Encrypt, Decrypt, Sign, and VerifySignature) |
eaSecp256k1 | ECDH/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:
- Key (required)
- PublicKey (required)
- ComputeSecretKDF (optional)
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:
- Key (required)
- HashAlgorithm (applicable to secp256r1, secp384r1, and secp521r1 only)
- HashEdDSA (applicable to ed25519 and ed448 only)
- HashValue (not applicable to PureEdDSA)
- UseHex
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:
- HashSignature (required)
- SignerKey (required)
- EdDSAContext (applicable to ed25519 and ed448 only)
- HashAlgorithm (applicable to secp256r1, secp384r1, and secp521r1 only)
- HashEdDSA (applicable to ed25519 and ed448 only)
- HashValue (not applicable to PureEdDSA)
- UseHex
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:
- EncryptionAlgorithm
- HMACAlgorithm
- HMACOptionalInfo
- HMACKeySize
- IV
- KDF
- KDFHashAlgorithm
- KDFOptionalInfo
- UseHex
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:
- SetOutputStream
- OutputFile
- OutputMessage: The output data is written to this property if no other destination is specified.
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:
- EncryptionAlgorithm
- HMACAlgorithm
- HMACOptionalInfo
- HMACKeySize
- IV
- KDF
- KDFHashAlgorithm
- KDFOptionalInfo
- UseHex
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:
- SetOutputStream
- OutputFile
- OutputMessage: The output data is written to this property if no other destination is specified.
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.
ComputeSecretKDF | The key derivation function. |
EncryptionAlgorithm | The encryption algorithm to use. |
HashAlgorithm | The hash algorithm used for hash computation. |
HashEdDSA | Whether to use HashEdDSA when signing with an ed25519 or ed448 key. |
HashSignature | The hash signature. |
HashValue | The hash value of the data. |
HMACAlgorithm | The HMAC algorithm to use during encryption. |
InputFile | The file to process. |
InputMessage | The message to process. |
IV | The initialization vector (IV) used when encrypting. |
KDF | The key derivation function used during encryption and decryption. |
KDFHashAlgorithm | The KDF hash algorithm to use when encrypting and decrypting. |
Key | The ECC key. |
OutputFile | The output file when encrypting or decrypting. |
OutputMessage | The output message when encrypting or decrypting. |
Overwrite | Indicates whether or not the component should overwrite files. |
RecipientKey | The public key used to compute the shared secret. |
SharedSecret | The computed shared secret. |
SignerKey | The public key used to verify the signature. |
UseHex | Whether 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.
ComputeSecret | Computes a shared secret. |
Config | Sets or retrieves a configuration setting. |
CreateKey | Creates a new key. |
Decrypt | Decrypted the specified data. |
Encrypt | Encrypts the specified data. |
Reset | Resets the component. |
SetInputStream | Sets the stream from which the component will read data to encrypt or decrypt. |
SetOutputStream | Sets the stream to which the component will write encrypted or decrypted data. |
Sign | Creates a hash signature using ECDSA or EdDSA. |
VerifySignature | Verifies 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.
Error | Information about errors during data delivery. |
Progress | Fired 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.
AppendSecret | An optional string to append to the secret agreement. |
CNGECDHKey | The CNG ECDH key. |
CNGECDSAKey | The CNG ECDSA key. |
ConcatAlgorithmId | Specifies the AlgorithmId subfield of the OtherInfo field. |
ConcatHashAlgorithm | The hash algorithm to use when ComputeSecretKDF is Concat. |
ConcatPartyUInfo | Specifies the PartyUInfo subfield of the OtherInfo field. |
ConcatPartyVInfo | Specifies the PartyVInfo subfield of the OtherInfo field. |
ConcatSuppPrivInfo | Specifies the SuppPrivInfo subfield of the OtherInfo field. |
ConcatSuppPubInfo | Specifies the SuppPubInfo subfield of the OtherInfo field. |
ECDSASignatureFormat | The format of the HashSignature when using ECDSA keys. |
EdDSAContext | A hex encoded string holding the bytes of the context when signing or verifying with ed25519ctx. |
EncryptionKeySize | The encryption key size. |
HMACKey | A key to use when generating a Hash-based Message Authentication Code (HMAC). |
HMACKeySize | Specifies the HMAC key size to be used during encryption. |
HMACOptionalInfo | Optional data to be used during encryption and decryption during the HMAC step. |
KDFOptionalInfo | Optional data to be used during encryption and decryption during the key derivation step. |
PrependSecret | An optional string to prepend to the secret agreement. |
StrictKeyValidation | Whether to validate provided public keys based on private keys. |
TLSLabel | The TLS PRF label. |
TLSSeed | The TLS PRF Seed. |
BuildInfo | Information about the product's build. |
CodePage | The system code page used for Unicode to Multibyte translations. |
LicenseInfo | Information about the current license. |
UseInternalSecurityAPI | Tells the component whether or not to use the system security libraries or an internal implementation. |