CryptoSys PKI Pro Manual

Cms.MakeEnvData(String, String, String, CipherAlgorithm, Cms.KeyEncrAlgorithm, HashAlgorithm, Cms.EnvDataOptions, Kdf.KdfAlg, Kdf.KeyWrapAlg, String, Int32, Cms.ContentEncrAlg) Method

Create a CMS enveloped-data object (advanced options).

Syntax

[C#]
public static int MakeEnvData(
   string outputFile,
   string inputFile,
   string certList,
   CipherAlgorithm cipherAlg = ,
   Cms.KeyEncrAlgorithm keyEncrAlg = Cms.KeyEncrAlgorithm.Default,
   HashAlgorithm hashAlg = HashAlgorithm.Sha1,
   Cms.EnvDataOptions advOptions = Cms.EnvDataOptions.None,
   Kdf.KdfAlg kdfAlg = Kdf.KdfAlg.X963,
   Kdf.KeyWrapAlg keyWrapAlg = Kdf.KeyWrapAlg.Default,
   string keyString = "",
   int count = 0,
   Cms.ContentEncrAlg contEncrAlg = Cms.ContentEncrAlg.Aes128 
)
[VB]
Public Shared Function MakeEnvData (
   outputFile As String,
   inputFile As String,
   certList As String,
   Optional cipherAlg As CipherAlgorithm = ,
   Optional keyEncrAlg As Cms.KeyEncrAlgorithm = Cms.KeyEncrAlgorithm.Default,
   Optional hashAlg As HashAlgorithm = HashAlgorithm.Sha1,
   Optional advOptions As Cms.EnvDataOptions = Cms.EnvDataOptions.None,
   Optional kdfAlg As Kdf.KdfAlg = Kdf.KdfAlg.X963,
   Optional keyWrapAlg As Kdf.KeyWrapAlg = Kdf.KeyWrapAlg.Default,
   Optional keyString As String = "",
   Optional count As Integer = 0,
   Optional contEncrAlg As Cms.ContentEncrAlg = Cms.ContentEncrAlg.Aes128 
) As Integer

Parameters

outputFile  String
Name of output file to be created.
inputFile  String
Input data file.
certList  String
List of one or more recipient X.509 certificate filenames, separated by semicolons (;). A certificate's representation in base64 or as a PEM string may be used instead of a filename. Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b).

Special cases: Set as "type=@pwri" to create a single recipientInfo of the PasswordRecipientInfo (pwri) type; or set as "type=@kekri,keyid=<string>" to create a single recipientInfo of the KEKRecipientInfo (kekri) type. See Remarks.

cipherAlg  CipherAlgorithm  (Optional)
Content encryption algorithm [default=ignored]. Deprecated: use contEncrAlg. (This parameter will be removed in a future update)
keyEncrAlg  Cms.KeyEncrAlgorithm  (Optional)
Key encryption algorithm for ktri type [default=RSAES-PKCS-v1_5)]
hashAlg  HashAlgorithm  (Optional)
Hash function where applicable. Must be one of the SHA-* family [default=SHA-1; SHA-256 for RSA-KEM]
advOptions  Cms.EnvDataOptions  (Optional)
Advanced options.
kdfAlg  Kdf.KdfAlg  (Optional)
Key derivation function (KDF) for ECDH key agreement scheme (where applicable)
keyWrapAlg  Kdf.KeyWrapAlg  (Optional)
Key wrap algorithm for ECDH key agreement scheme or kekri type (default=match content encryption algorithm)
keyString  String  (Optional)
(formerly ukmString) Use to pass optional additional user key material (ukm) for KDF where KeyAgreement (kari) type is used. Or use to pass the password for a pwri type or the key encryption key (KEK) for a kekri type. Either pass a plain ASCII string, e.g. "abc" or use the format "#x<hex-digits>" to pass a string of arbitrary octet values, e.g. "#xdeadbeef01" to pass the 5 bytes 0xde,0xad,0xbe,0xef,0x01. Required for pwri and kekri types.
count  Int32  (Optional)
Optional iteration count for KDF in pwri type (default=4096) or tag length for AuthEnvelopedData (in range 12-16, default=16). Otherwise ignored.
contEncrAlg  Cms.ContentEncrAlg  (Optional)
Preferred way to specify content encryption algorithm with more options. Takes precedence over cipherAlg. [default=AES128-CBC]

Return Value

Int32
Number of successful recipients or a negative error code.

Remarks

The output is a file containing a CMS EnvelopedData object or AuthEnvelopedData object. New in [v22.0] use the preferred contEncrAlg parameter to specify the content-encryption algorithm rather than cipherAlg. If a list of certificates is passed in certList, the recipientInfo type is set automatically depending on the public key found in each certificate, one for each certificate. If the public key is RSA (rsaEncryption) then the key transport technique (ktri) will be used for that particular recipientInfo. If the public key is a supported ECC key, then the standard ECDH ephemeral-static key agreement technique (kari) will be used as per [RFC5753] and [RFC8418].

Alternatively, use key encryption option Cms.KeyEncrAlgorithm.Rsa_Kem with an RSA public key, and the RSA-KEM algorithm using KEMRecipientInfo will be used for key encryption.

If certList is set to "type=@pwri" then a single recipientInfo will be created of PasswordRecipientInfo type (pwri). The password must be passed in the keyString parameter. The parameters keyEncrAlg, kdfAlg and keyWrapAlg are ignored in this case. If certList is set to "type=@kekri,keyid=<string>" then a single recipientInfo will be created of KEKRecipientInfo type (kekri). The key encryption key (KEK) must be passed in the keyString parameter. The parameters keyEncrAlg, hashAlg and kdfAlg are ignored in this case.

Example

// Create an enveloped CMS object (ktri type) to Bob using Bob's RSA key
n = Cms.MakeEnvData("cms2bob_aes128.p7m", "excontent.txt", "BobRSASignByCarl.cer", CipherAlgorithm.Aes128, Cms.KeyEncrAlgorithm.Rsa_Oaep);

// Create an enveloped CMS object (kekri type) using a previously distributed symmetric key-encryption key (KEK) 
n = Cms.MakeEnvData("cms_envdata_kekri.p7m", "excontent.txt", "type=@kekri,keyid=ourcommonkey", CipherAlgorithm.Aes256, 
        hashAlg: HashAlgorithm.Sha256, keyWrapAlg:Kdf.KeyWrapAlg.Aes128_wrap, keyString: "#x0123456789ABCDEFF0E1D2C3B4A59687");

See Also

VB6/C equivalent: CMS_MakeEnvData

[Contents] [Index]

[PREV: Cms.MakeEnvData(String, String, String, CipherAlgorithm, Cms.EnvDataOptions) Method...]   [Contents]   [Index]   
   [NEXT: Cms.MakeEnvDataFromBytes Method...]

Copyright © 2004-26 D.I. Management Services Pty Ltd t/a CryptoSys. All rights reserved. Generated 2026-09-21T05:59:39Z.