h DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('QC2LE') ** ** EncryptData API prototype d EncryptData Pr Extproc('Qc3EncryptData') d clearData 65535A const Options(*Varsize) d clearDatalen 10I 0 Const d clearDataFmt 8A Const d algoDescr 64A Const Options(*Varsize) d algoFormat 8A Const d keyDescriptor 512A Const Options(*Varsize) d keyFormat 8A Const d cryptoService 1A Const d cryptoDevName 10A Const options(*omit) d encryptedData... d 65535A Options(*Varsize) d encryptedDataLen... d 10I 0 Const d encryptedDataReturnLen... d 10I 0 d error 32767A Options( *VarSize ) ** ** DecryptData API prototype d DecryptData Pr Extproc('Qc3DecryptData') d encryptedData... d 65535A Const Options(*Varsize) d encryptedDataLen... d 10I 0 Const d algoDescr 64A Const Options(*Varsize) d algoFormat 8A Const d keyDescriptor 512A Const Options(*Varsize) d keyFormat 8A Const d cryptoService 1A Const d cryptoDevName 10A Const options(*omit) d clearData 65535A Options(*Varsize) d clearDatalen 10I 0 Const d clearDataReturnLen... d 10I 0 d error 32767A Options( *VarSize ) ** ** Generate pseudorandom numbers d GenRndNbr Pr ExtProc( 'Qc3GenPRNs' ) d PrnDta 1024a Options( *VarSize ) d PrnDtaLen 10i 0 Const d PrnTyp 1a Const d PrnPar 1a Const d Error 32767a Options( *VarSize ) ** ** Convert character to hex D cvtch Pr ExtProc( 'cvtch' ) D RcvChr * Value D SrcHex * Value D SrcLen 10i 0 Value ** ** Convert hex to character D cvthc Pr ExtProc( 'cvthc' ) D RcvHex * Value D SrcChr * Value D RcvLen 10i 0 Value ** ** Display long text: D DspLngTxt Pr ExtPgm( 'QUILNGTX' ) D DtLngTxt 32767a Const Options( *VarSize ) D DtLngTxtLen 10i 0 Const D DtMsgId 7a Const D DtMsgF 20a Const D DtError 32767a Const Options( *VarSize ) ** ** Set algorithm and key description structure d SetAlgoKeyDesFmt200... d Pr d keyString 16A Const ** ** ALGD0200 algorithm description structure d ALGD0200Des ds Qualified d BlkCphAlgo 10I 0 d BlkLen 10I 0 d Mode 1A d PadOpt 1A d PadChar 1A d Resvd 1A d MAClen 10I 0 d EffKeySiz 10I 0 d InitVct 32A ** ** KEYD0200 key description format structure d KEYD0200Des ds Qualified d KeyType 10I 0 d KeyStrLen 10I 0 d KeyFormat 1A d Resvd 3A d Key 16A ** ** Error structure D ERRC0100 ds Qualified D BytPrv 10i 0 Inz( %Size( ERRC0100 )) D BytAvl 10i 0 D MsgId 7a D 1a D MsgDta 128a ** d InputData s 17A Inz('It is secret info') d EncryptedData s 32A Inz(*Blanks) d DecryptedData s 32A Inz(*Blanks) d rtnLen s 10I 0 d csp s 1A Inz('1') d KeyStrChr s 16A Inz(*Blanks) d KeyStrHex s 32A Inz(*Blanks) d KeyStrChrC s 16A Inz(*Blanks) d MsgStr s 590A Inz(*Blanks) D Blanks s 48a ** /free //set algorithm and key description format CallP GenRndNbr( KeyStrChr : %size( KeyStrChr ) : '0' : '0' : ERRC0100 ); // convert char to hex CallP cvthc( %Addr( KeyStrHex ) : %Addr( KeyStrChr ) : %Len( %trim( KeyStrChr )) * 2 ); //set algorithm and key description format CallP SetAlgoKeyDesFmt200( KeyStrChr ); //encrypt data CallP EncryptData( InputData : %len(InputData) : 'DATA0100' : ALGD0200Des : 'ALGD0200' : KEYD0200Des : 'KEYD0200' : csp : *omit : EncryptedData : %size(EncryptedData) : rtnLen : ERRC0100 ); if ERRC0100.BytAvl = 0; MsgStr = 'Data string . . : ' + %Trim( InputData ) + Blanks + 'Key string C. . : ' + %Trim( KeyStrChr ) + Blanks + 'Key string H. . : ' + %Trim( KeyStrHex ) + Blanks + 'Cipher string . : ' + %Trim( EncryptedData ); CallP DspLngTxt( MsgStr : %Len( MsgStr ) : *Blanks : *Blanks : ERRC0100 ); else; dsply ERRC0100.MsgId; endif; // convert hex to char CallP cvtch( %Addr( KeyStrChrC ) : %Addr( KeyStrhex ) : %Len( %trim( KeyStrHex )) ); //decrypt data CallP DecryptData( EncryptedData : %len(EncryptedData) : ALGD0200Des : 'ALGD0200' : KEYD0200Des : 'KEYD0200' : csp : *omit : DecryptedData : %size(DecryptedData) : rtnLen : ERRC0100 ); if ERRC0100.BytAvl = 0; MsgStr = 'Data string . . : ' + %Trim( InputData ) + Blanks + 'Key string C. . : ' + %Trim( KeyStrChr ) + Blanks + 'Key string H. . : ' + %Trim( KeyStrHex ) + Blanks + 'Cipher string . : ' + %Trim( EncryptedData ) + Blanks + 'Key string H. . : ' + %Trim( KeyStrHex ) + Blanks + 'Key string C. . : ' + %Trim( KeyStrChrC ) + Blanks + 'Clear text . . : ' + %Trim( DecryptedData ); CallP DspLngTxt( MsgStr : %Len( MsgStr ) : *Blanks : *Blanks : ERRC0100 ); else; dsply ERRC0100.MsgId; endif; *inlr = *on; return; /end-free **-- Subprocedure definition -------------------------------------------** p SetAlgoKeyDesFmt200... p b d SetAlgoKeyDesFmt200... d pi d keyString 16A Const /free //set Algorithm Description ALGD0200Des.BlkCphAlgo = 22; ALGD0200Des.BlkLen = 16; ALGD0200Des.Mode = '0'; ALGD0200Des.PadOpt = '1'; ALGD0200Des.PadChar = x'00'; ALGD0200Des.Resvd = x'00'; ALGD0200Des.MAClen = *zero; ALGD0200Des.EffKeySiz = *zero; ALGD0200Des.InitVct = *Allx'00'; //set Key Description KEYD0200Des.KeyType = 22; KEYD0200Des.KeyStrLen = 16; KEYD0200Des.KeyFormat = '0'; KEYD0200Des.Resvd = *Allx'00'; KEYD0200Des.Key = keyString; /end-free p SetAlgoKeyDesFmt200... p e |