0% found this document useful (0 votes)
219 views4 pages

Upload 15

The document contains code to encrypt and decrypt data using the Qc3EncryptData and Qc3DecryptData API functions. It defines data structures for the encryption algorithm, key, and error handling. The code takes input data and key, encrypts it using RC4, stores the encrypted data in the output variable, and resets the error structure.

Uploaded by

rachmat99
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
219 views4 pages

Upload 15

The document contains code to encrypt and decrypt data using the Qc3EncryptData and Qc3DecryptData API functions. It defines data structures for the encryption algorithm, key, and error handling. The code takes input data and key, encrypts it using RC4, stores the encrypted data in the output variable, and resets the error structure.

Uploaded by

rachmat99
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

H BNDDIR('QC2LE') H DFTACTGRP(*NO) H OPTION(*NODEBUGIO:*SRCSTMT) *-----------------------------------------------** E N T R Y P A R M S ** *-----------------------------------------------d d d d d d d d d d d d d d encrypt inmode invalue inkey outvalue encrypt inmode invalue inkey outvalue

workmode workinvalue workinkey workoutvalue pr 1a 30a 30a 30a pi 1a 30a 30a 30a s s s s 1a 30a 30a 30a

*-----------------------------------------------** E N C R Y P T D A T A ** *-----------------------------------------------D Qc3EncryptData PR ExtProc('Qc3EncryptData') D szClearData 65535A OPTIONS(*VARSIZE) D nLenClearData 10I 0 Const D clearDataFmt 8A Const D AlgoDescript D szAlgoFormat D KeyDescriptor D szKeyFormat 64A 8A 512A 8A Const OPTIONS(*VARSIZE) Const Const OPTIONS(*VARSIZE) Const

** 0=Best choice, 1=Software, 2=Hardware D CryptoService 1A Const ** Hardware Cryptography device name or *BLANKS D CryptoDevName 10A Const D D D D D D D D szEncryptedData... 65535A nEncryptedDataVarLen... 10I 0 Const nEncryptedDataRtnLen... 10I 0 api_ErrorDS LikeDS(API_ErrorDS_T) OPTIONS(*VARSIZE) OPTIONS(*VARSIZE)

*-----------------------------------------------** D E C R Y P T D A T A ** *-----------------------------------------------D Qc3DecryptData PR ExtProc('Qc3DecryptData')

D szEncData D nLenEncData D AlgoDescript D szAlgoFormat D KeyDescriptor D szKeyFormat

65535A OPTIONS(*VARSIZE) 10I 0 Const 64A 8A 512A 8A Const OPTIONS(*VARSIZE) Const Const OPTIONS(*VARSIZE) Const

** 0=Best choice, 1=Software, 2=Hardware D CryptoService 1A Const ** Hardware Cryptography device name or *BLANKS D CryptoDevName 10A Const D D D D D 65535A OPTIONS(*VARSIZE) 10I 0 Const 10I 0 LikeDS(API_ErrorDS_T) OPTIONS(*VARSIZE) *-----------------------------------------------** Message Digest/Hash *-----------------------------------------------D Qc3CalcHash PR ExtProc('Qc3CalculateHash') D szClearData 65535A OPTIONS(*VARSIZE) D nLenClearData 10I 0 Const D clearDataFmt 8A Const D AlgoDescr D szAlgoFormat 64A 8A Const OPTIONS(*VARSIZE) Const szClearData nClearVarLen nRtnClearLen api_ErrorDS

** 0=Best choice, 1=Software, 2=Hardware D CryptoService 1A Const ** Hardware Cryptography device name or *BLANKS D CryptoDevName 10A Const D rtnHash 64A OPTIONS(*VARSIZE) D api_ErrorDS LikeDS(API_ErrorDS_T) D OPTIONS(*VARSIZE) *-----------------------------------------------** Cryptography API Algorithm ALGD0300 Structure *-----------------------------------------------D ALGD0300_T DS Qualified D BASED(DS_TEMPL) ** Stream algorithm: 30 = RC4 D Algorithm 10I 0 D D D D D D D D Qc3CreateAlgorithmContext... PR AlgoDescription... szAlgoFormat contextToken api_ErrorDS 64A 8A 8A ExtProc('Qc3CreateAlgorithmContext') Const OPTIONS(*VARSIZE) Const LikeDS(API_ErrorDS_T) OPTIONS(*VARSIZE) Qualified BASED(DS_TEMPL) Qualified

** Encryption Data Structures D KEYD0100_T DS D D keyContext 8A D KEYD0200_T DS

D D D D D

BASED(DS_TEMPL) 10I 0 10I 0 1A 256A Qualified 10I 0 Inz 10I 0 Inz 7A 1A Inz(X'00') 64A

type length format value /IF DEFINED(*V5R1M0) D API_ErrorDS_T DS D dsLen D rtnLen D cpfMsgID D apiResv1 D apiExcDta1 /ENDIF D D D D D D D D D D D ** New IBM API Error DS XT_api_ErrorEx DS XT_apiKey XT_apiDSLen XT_apiRtnLenEx... XT_apiMsgIDEx XT_apiResvdEx XT_apiCCSID XT_apiOffExc XT_apiExcLen XT_apiExcData

Inz 10I 0 10I 0 10I 7A 1A 10I 10I 10I 64A 0 0 0 0

D Qc3DestroyAlgorithmContext... D PR D ContextToken 8A D api_ErrorDS D ** API Error Data structure D QUSEC_EX DS D D charKey D nErrorDSLen D nRtnLen D msgid D Reserved D CCSID D OffsetExcp D excpLen D excpData D D D D D D D D D D ALGO_DES ALGO_TDES ALGO_AES ALGO_RC4 ALGO_RSA_PUB ALGO_RSA_PRIV ANY_CRYPTO_SRV SWF_CRYPTO_SRV HWD_CRYPTO_SRV CRYPTO_SRV C C C C C C C C C S

ExtProc('Qc3DestroyAlgorithmContext') Const LikeDS(API_ErrorDS_T) OPTIONS(*VARSIZE) Qualified Based(TEMPLATE_T)

10I 10I 10I 7A 1A 10I 10I 10I 128A

0 0 0 0 0 0 Const(20) Const(21) Const(22) Const(30) Const(50) Const(51) Const('0') Const('1') Const('2') Inz(*BLANKS) LikeDS(ALGD0300_T)

10A

** Cipher API data structures. D myAlgo DS

D myKey D apiError

DS DS

LikeDS(KEYD0200_T) LikeDS(qusec_ex)

** The clear text (data to be encrypted) ** The length of the data returned by the APIs D nRtnLen S 10I 0 ** The encrypted data variable D encData S 500A /free workinvalue = invalue; workinkey = inkey; workoutvalue = outvalue; myAlgo.Algorithm = ALGO_RC4; myKey.type = ALGO_RC4; myKey.length = %Len(%TrimR(workinkey)); myKey.Format = '0'; myKey.value = %TrimR(workinkey); apiError = *ALLX'00'; apiError.nErrorDSLen=%size(apiError);

select; when inmode = 'E'; Qc3EncryptData(workinvalue:%len(%TrimR(workinvalue)):'DATA0100': myAlgo : 'ALGD0300' : myKey : 'KEYD0200' : ANY_CRYPTO_SRV : CRYPTO_SRV : encData : %size(encData) : nRtnLen : apiError ); outvalue = encData; apiError = *ALLX'00'; apiError.nErrorDSLen=%size(apiError);

when inmode = 'D'; Qc3DecryptData(workinvalue : %len(%TrimR(workinvalue)) : myAlgo : 'ALGD0300' : myKey : 'KEYD0200' : ANY_CRYPTO_SRV : CRYPTO_SRV : outvalue : %size(outvalue) : nRtnLen : apiError ); endsl; *inlr = *on; /end-free

You might also like