# RXS_Crypt() This subprocedure performs cryptographic operations like hashing and encryption. Currently supported operations are: * MD5 * SHA1 * SHA256 * SHA384 * SHA512 ## Subprocedure Prototype ### IBM i 7.1+ | Field | Description | |---|---| | ` D RXS_Crypt... D PR Extproc('RXS_Crypt') Opdesc D Like(RXS_Var16Mv_t) D Rtnparm` | Returns the output of the specified hashing/crytographic operation is returned. | | ` D Input Like(RXS_Var16Mv_t) Const D Options(*Varsize)` | Field to hold the input of the selected hashing/crytographic operation. You can pass a field smaller than 16M without any additional effort. | | ` D DS Like(RXS_Var64K_t) D Options(*Varsize)` | Holds settings which control how RXS_Crypt operates. This parm can accomodate a number of possible data structures, listed below. | ### IBM i 6.1 | Field | Description | |---|---| | ` D RXS_Crypt... D PR Extproc('RXS_Crypt') Opdesc` | | | ` D Output Like(RXS_Var16Mv_t) D Options(*Varsize)` | Field to hold the output of the selected hashing/crytographic operation. Note that if you pass a field smaller than 16M, you will need to specify the length of the Output in the subfield OutputLength. | | ` D Input Like(RXS_Var16Mv_t) Const D Options(*Varsize)` | Field to hold the input of the selected hashing/crytographic operation. You can pass a field smaller than 16M without any additional effort. | | ` D DS Like(RXS_Var64K_t) D Options(*Varsize)` | Holds settings which control how RXS_Crypt operates. This parm can accomodate a number of possible data structures, listed below. | ## Example Code ### IBM i 7.1+ #### Example 1: MD5 Hash of Character Field ```rpgle *-------------------------------------------------------------- * This example code calculates an MD5 hash from a character field. *-------------------------------------------------------------- H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER) /copy QRPGLECPY,RXSCB D HashMD5DS DS LikeDS(RXS_MD5CryptDS_t) D Data S Like(RXS_Var1Kv_t) D Hash S Like(RXS_Var1Kv_t) /free Data = 'Hello World'; RXS_ResetDS( HashMD5DS : RXS_DS_TYPE_MD5CRYPT ); Hash = RXS_Crypt( Data : HashMD5DS ); RXS_JobLog( 'Hash: %s' : Hash ); // Output: Hash: B10A8DB164E0754105B7A99BE72E3FE5 *INLR = *ON; /end-free ``` ### IBM i 6.1 #### Example 1: MD5 Hash of Character Field ```rpgle *-------------------------------------------------------------- * This example code calculates an MD5 hash from a character field. *-------------------------------------------------------------- H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER) /define RXSV6R1 /copy QRPGLECPY,RXSCB D HashMD5DS DS LikeDS(RXS_MD5CryptDS_t) D Data S Like(RXS_Var1Kv_t) D Hash S Like(RXS_Var1Kv_t) /free Data = 'Hello World'; RXS_ResetDS( HashMD5DS : RXS_DS_TYPE_MD5CRYPT ); RXS_Crypt( Hash : Data : HashMD5DS ); RXS_JobLog( 'Hash: %s' : Hash ); // Output: Hash: B10A8DB164E0754105B7A99BE72E3FE5 *INLR = *ON; /end-free ``` ## Data Structures ### RXS_MD5CryptDS_t | Field | Description | |---|---| | ` D RXS_MD5CryptDS_t... D DS Qualified Template Inz` | | | ` D ReturnedErrorInfo... D LikeDS(RXS_ReturnedErrorInfoDS_t) Inz` | | | ` D OnErrorMessageType... D 10I 0` | | | ` D InputStmf Like(RXS_Var1Kv_t)` | Optional IFS stream file to use as input data for hash operation. | | ` D InputCcsid 10I 0 Inz(RXS_CCSID_JOB)` | CCSID of input data. Used when the input data is of a different CCSID of the job CCSID. Not necessary if using InputStmf. | | ` D EncryptAsCcsid... D 10I 0 Inz(RXS_CCSID_ISO88591)` | CCSID to convert the input data into before hashing. Note that this is typically going to be RXS_CCSID_ISO88591 or RXS_CCSID_UTF8. | | ` D InputPointer... D *` | **Internal use only** | | ` D InputLength 10I 0` | **Internal use only** | | ` D OutputPointer... D *` | **Internal use only** | | ` D OutputLength 10I 0` | **Internal use only** | | ` D Reserved 2048A` | **Internal use only** | ### RXS_SHACryptDS_t | Field | Description | |---|---| | ` D RXS_SHACryptDS_t... D DS Qualified Template Inz` | | | ` D ReturnedErrorInfo... D LikeDS(RXS_ReturnedErrorInfoDS_t) Inz` | | | ` D OnErrorMessageType... D 10I 0` | | | ` D Algorithm 4P 3` | Determines which SHA algorithm/block size to use when hashing. **Valid Values:** `RXS_CRYPT_SHA1_ALGORITHM`, `RXS_CRYPT_SHA256_ALGORITHM`, `RXS_CRYPT_SHA384_ALGORITHM`, `RXS_CRYPT_SHA512_ALGORITHM` | | ` D InputStmf Like(RXS_Var1Kv_t)` | Optional IFS stream file to use as input data for hash operation. | | ` D InputCcsid 10I 0 Inz(RXS_CCSID_JOB)` | CCSID of input data. Used when the input data is of a different CCSID of the job CCSID. Not necessary if using InputStmf. | | ` D EncryptAsCcsid... D 10I 0 Inz(RXS_CCSID_ISO88591)` | CCSID to convert the input data into before hashing. Note that this is typically going to be RXS_CCSID_ISO88591 or RXS_CCSID_UTF8. | | ` D InputPointer... D *` | **Internal use only** | | ` D InputLength 10I 0` | **Internal use only** | | ` D OutputPointer... D *` | **Internal use only** | | ` D OutputLength 10I 0` | **Internal use only** | | ` D Reserved 2049A` | **Internal use only** |