cookie CmCrypt2

Description

CmCrypt2 encrypts or decrypts data using direct or indirect encryption (see Encryption Modes) via a CmContainer entry.

tmr_02

Triple Mode Redundancy-related information (TMR)

  • C, C++
  • C#
  • Python

Syntax

int CMAPIENTRY CmCrypt2(HCMSysEntry hcmse, CMULONG flCtrl, CMCRYPT2 *pcmCrypt, void* pvDest, CMUINT cbDest)

Parameter

hcmse contains a handle opened by CmAccess / CmAccess2. Access Mode must be Entry Access to the Firm Code:Product Code entry used for en-/decryption. For software encryption (CM_CRYPT_AES_ENC_CBC_DIRECT or CM_CRYPT_AES_DEC_CBC_DIRECT) this has to be NULL.

flCtrl contains the encryption or decryption command. Following commands are supported:

nav_open CM_CRYPT_DIRECT_ENC executes the direct symmetric encryption via a CmContainer entry. The length of bytes to encrypt must be exactly 16 bytes (for CM_CRYPT_AES) or between 0 and 32 bytes (for CM_CRYPT_ECIES and CM_CRYPT_ECIES_STD) - see structure hmtoggle_plus1 CMBASECRYPT2.

nav_open CM_CRYPT_DIRECT_DEC executes the direct symmetric decryption via a CmContainer entry. The length of bytes to decrypt must be exactly 16 bytes (for CM_CRYPT_AES) or between 0 and 32 bytes (for CM_CRYPT_ECIES and CM_CRYPT_ECIES_STD) - see CMBASECRYPT2.

information_weiss_klein26

Wibu-Systems recommends this mode since CBC is the most commonly used mode of operation.

Although CodeMeter supports also other older cryptographic modes. However, their use is not recommended.

For more information see the technical guideline TR-02102-1 "Cryptographic Mechanisms: Recommendations and Key Lengths" (courtesy translation) edited by the German Federal Office for Information Security, BSI (Bundesamt für Sicherheit in der Informationstechnik) (BSI).

nav_open CM_CRYPT_AES_ENC_CBC executes the indirect encryption using the AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that cbDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If cbDest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If cbDest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

nav_open CM_CRYPT_AES_DEC_CBC executes the indirect decryption using the AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that cbDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If cbDest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If cbDest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

nav_open CM_CRYPT_AES_ENC_CBC_DIRECT executes the encryption using the original AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that cbDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If cbDest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If cbDest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

It does not use any CodeMeter license, therefore use NULL for hcmse. The AES key has to be placed in mabDirectAesKey, the initialization vector in mabInitKey - both see structure hmtoggle_plus1 CMCRYPT2).

nav_open CM_CRYPT_AES_DEC_CBC_DIRECT executes the decryption using the original AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that cbDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If cbDest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If cbDest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

It does not use any CodeMeter license, therefore use NULL for hcmse. The AES key has to be placed in mabDirectAesKey, the initialization vector in mabInitKey - both see structure hmtoggle_plus1 CMCRYPT2).

pcmCrypt sets some needed data for the en-/decryption process (see CMCRYPT2).

pvDest contains the data to en-/decrypt.

cbDest contains the number of bytes to en-/decrypt stored in pvDest.  

Return

This function returns the number of en-/decrypted bytes. If an error occurred, 0 will be returned.

Notes

CmCrypt2() is supported since CodeMeter Version 4.30.

Syntax

This method is overloaded, i.e. the same method name is used with different type of parameters or different set of parameters.

information_weiss_klein26

Wibu-Systems recommends this mode since CBC is the most commonly used mode of operation.

Although CodeMeter supports also other older cryptographic modes. However, their use is not recommended.

For more information see the technical guideline TR-02102-1 "Cryptographic Mechanisms: Recommendations and Key Lengths" (courtesy translation) edited by the German Federal Office for Information Security, BSI (Bundesamt für Sicherheit in der Informationstechnik) (BSI).

Method 1:

public bool CmCrypt2(HCMSysEntry hcmse, CmCryptOption Ctrl, CmCrypt2 Crypt, byte[] Dest, int StartIndex, uint DestLen)

This method overload encrypts and decrypts data in bytes with a StartIndex and DestLen as the total size of the destination buffer.

Method 2:

public bool CmCrypt2(HCMSysEntry hcmse, CmCryptOption Ctrl, CmCrypt2 Crypt, byte[] Dest)

This method overload encrypts and decrypts data in bytes as specified in the dest field of the method.

 

Parameter

hcmse contains a handle opened by CmAccess / CmAccess2. Access Mode must be Entry Access to the Firm Code : Product Code entry used for en-/decryption. For software encryption (CM_CRYPT_AES_ENC_CBC_DIRECT or CM_CRYPT_AES_DEC_CBC_DIRECT) this has to be NULL.

CmCryptOption contains the encryption or decryption command. Following commands are supported:

nav_open DirectEncryption executes the direct symmetric encryption via a CmContainer entry. The length of bytes to encrypt must be exactly 16 bytes (for Aes) or between 0 and 32 bytes (for Ecies and EciesStd) - see class hmtoggle_plus1 CmBaseCrypt2.

nav_open DirectDecryption executes the direct symmetric decryption via a CmContainer entry. The length of bytes to decrypt must be exactly 16 bytes (for Aes) or between 0 and 32 bytes (for Ecies and EciesStd) - see CmBaseCrypt.

nav_open AesEncryptCbc executes the indirect encryption using the AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that Dest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

Dest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If Dest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If Dest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

nav_open AesDecryptCbc executes the indirect decryption using the AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that Dest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

Dest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If Dest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If Dest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

nav_open AesEncryptCbcDirect executes the executes the encryption using the original AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that Dest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

Dest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If Dest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If Dest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

It does not use any CodeMeter license, therefore use NULL for hcmse. The AES key has to be placed in DirectAesKey, the initialization vector in InitKey - both see class hmtoggle_plus1 CmCrypt2).

nav_open AesDecryptCbcDirect executes the decryption using the original AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that Dest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

Dest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If Dest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If Dest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

It does not use any CodeMeter license, therefore use NULL for hcmse. The AES key has to be placed in DirectAesKey, the initialization vector in InitKey - both see CmCrypt2.

Crypt sets some needed data for the en-/decryption process (see CmCrypt2).

Dest contains the data to encrypt or decrypt.

Return

This function returns true. If an error occurred, false will be returned.

Notes

CmCrypt2() is supported since CodeMeter Version 4.30.

 

Syntax

import cmapi
handle.CmCrypt2(flCtrl: int, pcmCrypt: cmapi.CMCRYPT2, pvDest: bytes)
 -> bytes
throws CodeMeterApiFailedException()

Parameter

handle is the handle opened by CmAccess2. Access Mode must be Entry Access to the Firm Code:Product Code entry used for en-/decryption. For software encryption (cmapi.CM_CRYPT_AES_ENC_CBC_DIRECT or cmapi.CM_CRYPT_AES_DEC_CBC_DIRECT) this has to be NULL.

flCtrl contains the encryption or decryption command. Following commands are supported:

nav_open cmapi.CM_CRYPT_DIRECT_ENC executes the direct symmetric encryption via a CmContainer entry. The length of bytes to encrypt must be exactly 16 bytes (for cmapi.CM_CRYPT_AES) or between 0 and 32 bytes (for cmapi.CM_CRYPT_ECIES and cmapi.CM_CRYPT_ECIES_STD) - see class hmtoggle_plus1 cmapi.CMBASECRYPT2.

nav_open cmapi.CM_CRYPT_DIRECT_DEC executes the direct symmetric decryption via a CmContainer entry. The length of bytes to decrypt must be exactly 16 bytes (for cmapi.CM_CRYPT_AES) or between 0 and 32 bytes (for cmapi.CM_CRYPT_ECIES and CM_CRYPT_ECIES_STD) - see cmapi.CMBASECRYPT2.

information_weiss_klein26

Wibu-Systems recommends this mode since CBC is the most commonly used mode of operation.

Although CodeMeter supports also other older cryptographic modes. However, their use is not recommended.

For more information see the technical guideline TR-02102-1 "Cryptographic Mechanisms: Recommendations and Key Lengths" (courtesy translation) edited by the German Federal Office for Information Security, BSI (Bundesamt für Sicherheit in der Informationstechnik) (BSI).

nav_open cmapi.CM_CRYPT_AES_ENC_CBC executes the indirect encryption using the AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that pvDes is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

pvDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If the size equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If the size equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

nav_open cmapi.CM_CRYPT_AES_DEC_CBC executes the indirect decryption using the AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that pvDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

pvDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If the size equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If the size equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

nav_open cmapi.CM_CRYPT_AES_ENC_CBC_DIRECT executes the encryption using the original AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that pvDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

pvDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If the size equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If the size equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

It does not use any CodeMeter license, therefore use NULL for hcmse. The AES key has to be placed in mabDirectAesKey, the initialization vector in mabInitKey - both see structure hmtoggle_plus1 cmapi.CMCRYPT2).

nav_open cmapi.CM_CRYPT_AES_DEC_CBC_DIRECT executes the decryption using the original AES block cipher algorithm with CBC.

By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that pvDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.

information_weiss_klein26

cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen.

If the size equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS.

If the size equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB.

It does not use any CodeMeter license, therefore use NULL for hcmse. The AES key has to be placed in mabDirectAesKey, the initialization vector in mabInitKey - both see structure hmtoggle_plus1 CMCRYPT2).

pcmCrypt sets some needed data for the en-/decryption process (see cmapi.CMCRYPT2).

pvDest contains the data to en-/decrypt.

Return

This function returns the number of en-/decrypted bytes. If an error occurred, an exception will be thrown.

Notes

CmCrypt2() is supported since CodeMeter Version 4.30.