-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCtest.dbl
More file actions
804 lines (675 loc) · 22.8 KB
/
CCtest.dbl
File metadata and controls
804 lines (675 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
import SynPSG.Core.Utilities.CC
import SynPSG.Core.Utilities.Encryption
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;encryption styles
.define ENCRYPT_FIELD_INPLACE 1
.define ENCRYPT_FIELD 2
.define ENCRYPT_RECORD 3
;;when using AES encryption, use this AES type
.define ENCRYPTION_AES_TYPE EncryptionType.AES128
;;include this define to enable debug logging
;.define ENCRYPTION_DEBUG_FILE 'encryption.log'
;encryption type being used
;.define USING_ENCRYPTION_DES3
;.define USING_ENCRYPTION_AES
;used to manage record layout
;.define USING_ENCRYPTION_FIELD
;.define USING_ENCRYPTION_RECORD
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
main
.include 'WND:tools.def'
.include 'WND:inpctl.def'
global common
chan ,i4 ;channel for load method
encryptStyle ,i4 ;see ENCRYPT_* defines
endcommon
stack record
Encryption ,@SynPSG.Core.Utilities.Encryption.SynEncrypt
endrecord
stack record ccData
.include 'CCrec.inc'
endrecord
record
pos ,i4
errnum ,i4
bldid ,i4
colid ,i4
wndid ,i4
lstid ,i4
colid2 ,i4
wndid2 ,i4
req ,i4
ccTypeHdl ,i4
ccTypeMax ,i4
addMode ,boolean
mbuffer ,a1024
endrecord
structure ccTypeArray
description ,a15
endstructure
proc
u_start
call startup
;;build an array of credit card names
ccTypeHdl = %mem_proc(DM_ALLOC+DM_BLANK, ^size(ccTypeArray))
ccTypeMax = 1
repeat
begin
^m(ccTypeArray[ccTypeMax], ccTypeHdl) = SynPSG.Core.Utilities.CC.SynCC.getCCname(ccTypeMax)
if(!^m(ccTypeArray[ccTypeMax], ccTypeHdl))
exitloop
ccTypeMax += 1
ccTypeHdl = %mem_proc(DM_RESIZ+DM_BLANK, ccTypeMax*^size(ccTypeArray), ccTypeHdl)
end
if(ccTypeMax > 1)
ccTypeMax -= 1
;; build UI Toolkit list/menu to process a list of credit cards
mb_column(mbuffer, 'COL_MAIN', "File")
mb_entry(mbuffer, 'O_EXIT', "Exit", F4_KEY)
mb_entry(mbuffer, 'ADD_ITEM', "Create", F62_KEY)
mb_entry(mbuffer, 'MOD_ITEM', "Modify")
mb_entry(mbuffer, 'DEL_ITEM', "Delete", F63_KEY)
using encryptStyle select
(ENCRYPT_FIELD),
nop
(ENCRYPT_RECORD),
nop
(ENCRYPT_FIELD_INPLACE),
begin
mb_line(mbuffer)
mb_entry(mbuffer, 'ENCRYPT', "In-place Encryption of data",,,,, TRUE)
mb_entry(mbuffer, 'DECRYPT', "In-place Decryption of data")
end
(), ;;none
begin
mb_line(mbuffer)
mb_entry(mbuffer, 'ENCRYPT', "In-place Encryption of data")
mb_entry(mbuffer, 'DECRYPT', "In-place Decryption of data",,,,, TRUE)
end
endusing
mb_end(mbuffer, colid)
ib_input(bldid, 'CCLIST', 1, 100)
ib_dsp_area(bldid, 1, 1, 1, 75)
pos = 1
ib_field(bldid, 'customer', D_FLD_TYPE, D_ALPHA, D_FLD_SIZE, ^size(customer),
& D_FLD_FPOS, 1, pos)
pos += (^size(customer) + 1)
ib_field(bldid, 'ccHolder', D_FLD_TYPE, D_ALPHA, D_FLD_SIZE, ^size(ccHolder),
& D_FLD_FPOS, 1, pos)
pos += (^size(ccHolder) + 1)
ib_field(bldid, 'ccType', D_FLD_TYPE, D_DECIMAL, D_FLD_SIZE, ^size(ccType),
& D_FLD_FPOS, 1, pos,
& D_FLD_SELECT, 1, 1, 1, ^size(ccTypeArray), ccTypeMax, ^m(ccTypeArray[1], ccTypeHdl),
& D_FLD_ENUM, ^size(ccTypeArray), 1, 1)
pos += (^size(ccTypeArray[1]) + 1)
ib_field(bldid, 'ccExpiry', D_FLD_TYPE, D_DECIMAL, D_FLD_SIZE, ^size(ccExpiry),
& D_FLD_FPOS, 1, pos, D_FLD_BZRO)
pos += (^size(ccExpiry) + 1)
ib_field(bldid, 'ccNumber', D_FLD_TYPE, D_DECIMAL, D_FLD_SIZE, ^size(ccNumber),
& D_FLD_FPOS, 1, pos, D_FLD_BZRO)
pos += (^size(ccNumber) + 1)
ib_end(bldid, wndid)
l_class(bldid, 'LIST_CLASS',,, 10, 1,,,,,, 'ccTest_load',, errnum)
l_create(lstid, wndid, ccData,, 'LIST_CLASS',,,,,,, errnum)
getlog('ACTIVEX_LIST', mbuffer, errnum)
if(errnum > 0 && mbuffer != '0') then
l_sect(lstid, 'Customer|Cardholder|Type|Exp|Card#|', D_HEADER)
else
l_sect(lstid, 'Customer Cardholder Type Exp Card#', D_HEADER)
l_button(lstid, DSB_ADD, 'O_EXIT', DSB_TEXT, 'Exit')
l_button(lstid, DSB_ADD, 'ADD_ITEM', DSB_TEXT, 'Add')
l_button(lstid, DSB_ADD, 'DEL_ITEM', DSB_TEXT, 'Delete')
;;show list of credit cards on file
l_queue(lstid, D_LBOTTOM)
req = D_LTOP
repeat
begin
l_select(lstid, req, ccData,,,,,,,,,,,,, Encryption)
if(g_select) then
begin
using g_entnam select
('O_EXIT '),
exitloop
('MOD_ITEM '),
call mod_item
('ADD_ITEM '),
call add_item
('DEL_ITEM '),
call del_item
('ENCRYPT '),
begin
using encryptStyle select
(ENCRYPT_FIELD_INPLACE),
nop
(ENCRYPT_FIELD),
nop
(ENCRYPT_RECORD),
nop
(),
begin
clear Encryption
encryptStyle = ENCRYPT_FIELD_INPLACE
setupEncryption(encryptStyle, Encryption)
call inPlaceEncrypt
call set_window_title
m_disable(colid, 'ENCRYPT')
m_enable(colid, 'DECRYPT')
l_restart(lstid)
req = D_LNOP
end
endusing
end
('DECRYPT '),
begin
using encryptStyle select
(ENCRYPT_FIELD_INPLACE),
begin
call inPlaceDecrypt
clear Encryption
encryptStyle = 0
setupEncryption(encryptStyle, Encryption)
call set_window_title
m_disable(colid, 'DECRYPT')
m_enable(colid, 'ENCRYPT')
l_restart(lstid)
req = D_LNOP
end
(ENCRYPT_FIELD),
nop
(ENCRYPT_RECORD),
nop
(),
nop
endusing
end
endusing
end
else
begin
data isNull ,i4
l_status(lstid, D_LNULL, isNull)
if(!isNull)
call mod_item
end
end
flags(7000000,1)
stop D_EXIT_SUCCESS
;-----------------------------------------------------------------------------
edit_item,
m_column(D_REMOVE, colid)
mb_column(mbuffer, 'COL_OK', "File")
mb_entry(mbuffer, 'O_EXIT', "OK", F4_KEY)
mb_entry(mbuffer, 'O_QUIT', "Cancel", ESC_KEY)
mb_end(mbuffer, colid2)
ib_input(bldid, 'CCEDIT', 7, 60)
ib_field(bldid, 'customer', D_FLD_TYPE, D_ALPHA, D_FLD_SIZE, ^size(customer),
& D_FLD_FPOS, 2, 15, D_FLD_POS, 2, 2, D_FLD_PROMPT, "Customer")
ib_field(bldid, 'ccHolder', D_FLD_TYPE, D_ALPHA, D_FLD_SIZE, ^size(ccHolder),
& D_FLD_FPOS, 3, 15, D_FLD_POS, 3, 2, D_FLD_PROMPT, "Cardholder")
ib_field(bldid, 'ccType', D_FLD_TYPE, D_DECIMAL, D_FLD_SIZE, ^size(ccType),
& D_FLD_FPOS, 4, 15, D_FLD_POS, 4, 2, D_FLD_PROMPT, "Type",
& D_FLD_SELECT, 1, 1, 1, ^size(ccTypeArray), ccTypeMax, ^m(ccTypeArray[1],ccTypeHdl),
& D_FLD_ENUM, ^size(ccTypeArray), 1, 1)
ib_field(bldid, 'ccExpiry', D_FLD_TYPE, D_DECIMAL, D_FLD_SIZE, ^size(ccExpiry),
& D_FLD_FPOS, 5, 15, D_FLD_POS, 5, 2, D_FLD_PROMPT, "Expiry", D_FLD_BZRO)
ib_field(bldid, 'ccNumber', D_FLD_TYPE, D_DECIMAL, D_FLD_SIZE, ^size(ccNumber),
& D_FLD_FPOS, 6, 15, D_FLD_POS, 6, 2, D_FLD_PROMPT, "Cardnumber", D_FLD_BZRO,
& D_FLD_CHANGE, 'ccChange')
ib_end(bldid, wndid2)
b_button(wndid2, DSB_ADD, 'O_EXIT', DSB_TEXT, 'OK')
b_button(wndid2, DSB_ADD, 'O_QUIT', DSB_TEXT, 'Cancel')
u_window(D_PLACE, wndid2, 1 ,1)
if(addMode == TRUE) then
i_init(wndid2)
else
i_display(wndid2,, ccData)
i_next(wndid2,, '*FRST*')
if (addMode == FALSE)
i_disable(wndid2, 'customer')
repeat
begin
i_input(wndid2,, ccdata,,,, D_NOTERM)
if(g_select)
begin
using g_entnam select
('O_QUIT'),
exitloop
('O_EXIT'),
begin
if(!ccData.customer)
begin
u_message("Enter Customer")
i_next(wndid2,, 'customer')
nextloop
end
if(!ccData.ccHolder)
begin
u_message("Enter Cardholder name")
i_next(wndid2,, 'ccHolder')
nextloop
end
if(!ccData.ccType)
begin
u_message("Enter Credit card type")
i_next(wndid2,, 'ccType')
nextloop
end
if(!ccData.ccExpiry)
begin
u_message("Enter Credit card expiry")
i_next(wndid2,, 'ccExpiry')
nextloop
end
if(!ccData.ccNumber)
begin
u_message("Enter Credit card #")
i_next(wndid2,, 'ccNumber')
nextloop
end
exitloop
end
endusing
end
i_next(wndid2,, '*FRST*')
end
u_window(D_DELETE, wndid2)
m_column(D_DELETE, colid2)
m_column(D_PLACE, colid)
return
;-----------------------------------------------------------------------------
add_item,
l_process(lstid, req=D_LAPPEND, ccData)
addMode = TRUE
call edit_item
using g_entnam select
('O_EXIT'),
begin
call encrypt_data
store(chan, ccData) [ERR=storeError]
call decrypt_data
i_display(wndid,, ccData)
req = D_LNOP
exit
storeError,
u_message("Error "+%string(%error)+" updating file")
req = D_LDELITEM
end
(),
begin
req = D_LDELITEM
end
endusing
return
;-----------------------------------------------------------------------------
mod_item,
read(chan, ccData, ccData.customer) [ERR=writeError]
call decrypt_data
addMode = FALSE
call edit_item
using g_entnam select
('O_EXIT'),
begin
call encrypt_data
write(chan, ccData) [ERR=writeError]
call decrypt_data
i_display(wndid,, ccData)
req = D_LNOP
exit
writeError,
u_message("Error "+%string(%error)+" updating file")
req = D_LCANCEL
end
(),
begin
req = D_LCANCEL
end
endusing
return
del_item,
read(chan, ccData, ccData.customer) [ERR=deleteError]
delete(chan) [ERR=deleteError]
req = D_LDELITEM
if(FALSE)
begin
deleteError,
u_message("Error "+%string(%error)+" updating file")
req = D_LNOP
end
return
;-----------------------------------------------------------------------------
encrypt_data,
using encryptStyle select
(ENCRYPT_FIELD_INPLACE),
ccData.encryptedCC = Encryption.Encrypt(ccData.encryptedCC)
(ENCRYPT_FIELD),
ccData.encryptedCC = Encryption.Encrypt(ccData.encryptedCC.ccNumber)
(ENCRYPT_RECORD),
ccData.encryptedData = Encryption.Encrypt(ccData.encryptData)
endusing
return
;-----------------------------------------------------------------------------
decrypt_data,
using encryptStyle select
(ENCRYPT_FIELD_INPLACE),
ccData.encryptedCC = Encryption.Decrypt(ccData.encryptedCC)
(ENCRYPT_FIELD),
ccData.encryptedCC = Encryption.Decrypt(ccData.encryptedCC)
(ENCRYPT_RECORD),
ccData.encryptData = Encryption.Decrypt(ccData.encryptedData)
endusing
return
;-----------------------------------------------------------------------------
startup,
cmdln(mbuffer)
pos = %instr(1, mbuffer, '-delete ')
if(pos)
begin
delet('ccData.ism')
delet('ccData_F.ism')
delet('ccData_R.ism')
end
if(%instr(1, mbuffer, '-i '))
encryptStyle = ENCRYPT_FIELD_INPLACE
if(%instr(1, mbuffer, '-f '))
encryptStyle = ENCRYPT_FIELD
if(%instr(1, mbuffer, '-r '))
encryptStyle = ENCRYPT_RECORD
if(encryptStyle == 0)
begin
getlog('ENCRYPT_STYLE', mbuffer, pos)
if(pos)
using mbuffer select
('i'),
encryptStyle = ENCRYPT_FIELD_INPLACE
('f'),
encryptStyle = ENCRYPT_FIELD
('r'),
encryptStyle = ENCRYPT_RECORD
endusing
end
clear errnum
.ifdef USING_ENCRYPTION_DES3
errnum += 1
.endc
.ifdef USING_ENCRYPTION_AES
errnum += 1
.endc
using errnum select
(1),
begin
if(encryptStyle == 0)
begin
u_message("Environment Variable ENCRYPT_STYLE is not set - valid values are i|f|r")
stop D_EXIT_FAILURE
end
;;encryption required
end
(0),
begin
if(encryptStyle != 0 && encryptStyle != ENCRYPT_FIELD_INPLACE)
begin
u_message("Encryption defines ENCRYPTION_* are not set")
stop D_EXIT_FAILURE
end
;;no encryption required
end
(),
begin
u_message("More than one Encryption define ENCRYPTION_* is set")
stop D_EXIT_FAILURE
end
endusing
clear errnum, pos
.ifdef FLDS_ENCRYPT_FIELD_INPLACE
errnum += 1
pos = ENCRYPT_FIELD_INPLACE
.endc
.ifdef USING_ENCRYPTION_FIELD
errnum += 1
pos = ENCRYPT_FIELD
.endc
.ifdef USING_ENCRYPTION_RECORD
errnum += 1
pos = ENCRYPT_RECORD
.endc
using errnum select
(1, 0),
begin
if((pos == ENCRYPT_FIELD_INPLACE && encryptStyle == 0) ||
& (pos == 0 && encryptStyle == ENCRYPT_FIELD_INPLACE) )
exit ;;no encryption or encrypt in place = ok - records match
if(pos != encryptStyle)
begin
u_message("Encryption defines FLDS_ENCRYPT_* do not match environment variable ENCRYPT_STYLE")
stop D_EXIT_FAILURE
end
end
(),
begin
u_message("More than one Encryption define FLDS_ENCRYPT_* is set")
stop D_EXIT_FAILURE
end
endusing
.ifdef ENCRYPTION_DEBUG_FILE
;;delete logfile (if exists)
delet(ENCRYPTION_DEBUG_FILE)
;;Logical ENCRYPTION_DEBUG_FILENAME is used in the SynEncrypt constructor, to enable debug logging
setlog('ENCRYPTION_DEBUG_FILENAME', ENCRYPTION_DEBUG_FILE, errnum)
.else
;;no debug logging
setlog('ENCRYPTION_DEBUG_FILENAME',, errnum)
.endc ;ENCRYPTION_DEBUG_FILE
setupEncryption(encryptStyle, Encryption)
begin
;;Assign file name - uses different files, as encryption changes the length of the record.
;; and changing the filename will ensure the correct format between different encryption tests
data ccDataFileName ,a8
using encryptStyle select
(ENCRYPT_FIELD),
ccDataFileName = 'ccData_F'
(ENCRYPT_RECORD),
ccDataFileName = 'ccData_R'
(), ;;ENCRYPT_FIELD_INPLACE, none
ccDataFileName = 'ccData'
endusing
;; open credit card file
u_open(chan=%syn_freechn, 'U:I', ccDataFileName,,, errnum)
if(errnum)
begin
isamc(ccDataFileName, ^size(ccData), 1, 'start=1,len='+%string(^size(ccData.customer))+',nodups')
u_open(chan=%syn_freechn, 'U:I', ccDataFileName)
end
using encryptStyle select
(ENCRYPT_FIELD),
nop
(ENCRYPT_RECORD),
nop
(ENCRYPT_FIELD_INPLACE),
nop
(), ;;none
begin
;;assume not encrypted
encryptStyle = 0
;;try reading record, and see if the data is really encrypted
reads(chan, ccData, noData)
pos = 1
while(pos <= ^size(ccNumber))
begin
using ^a(ccNumber(pos:1)) select
('0' thru '9', ' '),
nop
(),
begin
;;invalid character, assume encrytped
encryptStyle = ENCRYPT_FIELD_INPLACE
exitloop
end
endusing
pos += 1
end
noData,
end
endusing
end
call set_window_title
;;check that the encrypted fields are the appropriate size
using encryptStyle select
(ENCRYPT_FIELD, ENCRYPT_FIELD_INPLACE),
begin
if (^size(encryptedCC) != Encryption.getEncryptedLength(ccNumber))
begin
u_message("EncryptedCC field "+%string(^size(encryptedCC))+" != "+%string(Encryption.getEncryptedLength(ccNumber)))
stop D_EXIT_FAILURE
end
end
(ENCRYPT_RECORD),
begin
if (^size(encryptedData) != Encryption.getEncryptedLength(encryptData))
begin
u_message("Encrypted Record "+%string(^size(encryptedData))+" != "+%string(Encryption.getEncryptedLength(encryptedData)))
stop D_EXIT_FAILURE
end
end
endusing
;;if we get here, then the test program harness is ok
return
;-----------------------------------------------------------------------------
set_window_title,
;; update application title, with encryption method
using encryptStyle select
(ENCRYPT_FIELD_INPLACE),
mbuffer = 'Encrypted field (in place)'
(ENCRYPT_FIELD),
mbuffer = 'Encrypted field'
(ENCRYPT_RECORD),
mbuffer = 'Encrypted record'
(),
mbuffer = 'No Encryption'
endusing
.ifdef USING_ENCRYPTION_DES3
mbuffer = '3DES ' + mbuffer
.endc
.ifdef USING_ENCRYPTION_AES
mbuffer = 'AES ' + mbuffer
.endc
e_sect(mbuffer(1:%trim(mbuffer)), D_CAPTION)
return
;-----------------------------------------------------------------------------
inPlaceEncrypt,
find(chan,, ^FIRST)
repeat
begin
reads(chan, ccData, eof)
ccData.encryptedCC = Encryption.Encrypt(ccData.encryptedCC)
write(chan, ccData) [ERR=writeError1]
writeError1,
end
eof,
return
;-----------------------------------------------------------------------------
inPlaceDecrypt,
find(chan,, ^FIRST)
repeat
begin
reads(chan, ccData, eof2)
ccData.encryptedCC = Encryption.Decrypt(ccData.encryptedCC)
write(chan, ccData) [ERR=writeError2]
writeError2,
end
eof2,
return
endmain
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
subroutine setupEncryption
req in aEncryptStyle ,i
req out aEncryption ,@SynPSG.Core.Utilities.Encryption.SynEncrypt
endparams
record
padBuffer ,i4
endrecord
proc
;;create Encryption class/object
using aEncryptStyle select
(ENCRYPT_FIELD, ENCRYPT_RECORD),
padBuffer = 1
(), ;;ENCRYPT_FIELD_INPLACE, none
padBuffer = 0
endusing
begin
.ifdef USING_ENCRYPTION_AES
data salt ,a8 ,'ABCDEFGH'
data IV ,a16 ,'ABCDEFGHIJKLMNOP'
aEncryption = new SynEncrypt(ENCRYPTION_AES_TYPE, salt, IV, padBuffer)
.else
data salt ,a8 ,'ABCDEFGH'
data IV ,a8 ,'ABCDEFGH'
aEncryption = new SynEncrypt(EncryptionType.DES3, salt, IV, padBuffer)
.endc
end
xreturn
endsubroutine
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; List load method
subroutine ccTest_load
a_listid ,n ; List id
a_req ,n ; Request flag
a_data ,a ; Item data
a_inpid ,n ; Input window id
a_disable ,n ; (Optional) Disable flag
a_index ,n ; Loading index
aEncryption ,@SynPSG.Core.Utilities.Encryption.SynEncrypt
endparams
.include "WND:tools.def"
record ccData
.include 'CCrec.inc'
external common
chan ,i4
encryptStyle ,i4
endcommon
proc
if(a_index == 1)
find(chan,, ^FIRST) [ERR=nomore_items]
reads(chan, ccData, nomore_items)
using encryptStyle select
(ENCRYPT_FIELD_INPLACE),
ccData.encryptedCC = aEncryption.Decrypt(ccData.encryptedCC)
(ENCRYPT_FIELD),
ccData.encryptedCC = aEncryption.Decrypt(ccData.encryptedCC)
(ENCRYPT_RECORD),
ccData.encryptData = aEncryption.Decrypt(ccData.encryptedData)
endusing
i_display(a_inpid,, ccData)
a_data = ccData
xreturn
nomore_items,
a_req = D_LEOF
clear a_data
xreturn
endsubroutine
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Change Method
function ccChange ,^val ,reentrant
a_data_entered ,a ; A buffer containg the field data as
; entered by the user.
a_data_stored ,a ; A buffer for the final storage of the
; data.
a_pending_status ,n ; The result of Toolkit's field
; validations.
.include "WND:inpinf.def" ; Group argument of input info
a_inprec ,a ; The data_area argument passed to the
; calling input routine.
endparams
.include "WND:tools.def"
record ccData
.include 'CCrec.inc'
proc
ccData = a_inprec
if(SynPSG.Core.Utilities.CC.SynCC.isValid(integer(ccData.ccType), a_data_entered) == FALSE)
begin
a_pending_status = D_EMITTEDERR
u_message("Invalid credit Card #")
end
freturn a_pending_status
endfunction
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++