File: w_main.srw
Size: 14653
Date: Sun, 01 Jan 2017 20:28:06 +0100
$PBExportHeader$w_main.srw
forward
global type w_main from window
end type
type cb_random from commandbutton within w_main
end type
type st_random from statictext within w_main
end type
type sle_random from singlelineedit within w_main
end type
type st_encrypt_label from statictext within w_main
end type
type cb_encrypt from commandbutton within w_main
end type
type cb_decrypt from commandbutton within w_main
end type
type st_encrypted_label from statictext within w_main
end type
type sle_source from singlelineedit within w_main
end type
type sle_encrypted from singlelineedit within w_main
end type
type sle_hashvalue from singlelineedit within w_main
end type
type st_hashvalue from statictext within w_main
end type
type cb_hash from commandbutton within w_main
end type
type sle_hashresult from singlelineedit within w_main
end type
type st_hashresult from statictext within w_main
end type
type dw_main from datawindow within w_main
end type
type cb_cancel from commandbutton within w_main
end type
end forward

global type w_main from window
integer width = 2784
integer height = 1420
boolean titlebar = true
string title = "Crypto API Test"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
cb_random cb_random
st_random st_random
sle_random sle_random
st_encrypt_label st_encrypt_label
cb_encrypt cb_encrypt
cb_decrypt cb_decrypt
st_encrypted_label st_encrypted_label
sle_source sle_source
sle_encrypted sle_encrypted
sle_hashvalue sle_hashvalue
st_hashvalue st_hashvalue
cb_hash cb_hash
sle_hashresult sle_hashresult
st_hashresult st_hashresult
dw_main dw_main
cb_cancel cb_cancel
end type
global w_main w_main

type variables
n_cryptoapi in_crypto

end variables

forward prototypes
public subroutine wf_populate ()
end prototypes

public subroutine wf_populate ();// populate DataWindow dropdowns

DWObject ldwo_type
DataWindowChild ldwc_type, ldwc_provider
String ls_Provider[], ls_find
ULong lul_ProvID[], lul_ProvType[]
Long ll_idx, ll_max, ll_find, ll_next

SetPointer(HourGlass!)

dw_main.GetChild("type_id", ldwc_type)
dw_main.GetChild("provider_id", ldwc_provider)

// populate dropdowns
ll_max = in_crypto.of_EnumProviders(lul_ProvID, ls_Provider, lul_ProvType)
For ll_idx = 1 To ll_max
   // add to Types dropdown
   ls_find = "id = " + String(lul_ProvType[ll_idx])
   ll_find = ldwc_type.Find(ls_find, 1, ldwc_type.RowCount())
   If ll_find = 0 Then
      ll_next = ldwc_type.InsertRow(0)
      ldwc_type.SetItem(ll_next, "id", lul_ProvType[ll_idx])
      choose case lul_ProvType[ll_idx]
         case in_crypto.PROV_RSA_FULL
            ldwc_type.SetItem(ll_next, "name", "PROV_RSA_FULL")
         case in_crypto.PROV_RSA_SIG
            ldwc_type.SetItem(ll_next, "name", "PROV_RSA_SIG")
         case in_crypto.PROV_DSS
            ldwc_type.SetItem(ll_next, "name", "PROV_DSS")
         case in_crypto.PROV_FORTEZZA
            ldwc_type.SetItem(ll_next, "name", "PROV_FORTEZZA")
         case in_crypto.PROV_MS_EXCHANGE
            ldwc_type.SetItem(ll_next, "name", "PROV_MS_EXCHANGE")
         case in_crypto.PROV_SSL
            ldwc_type.SetItem(ll_next, "name", "PROV_SSL")
         case in_crypto.PROV_RSA_SCHANNEL
            ldwc_type.SetItem(ll_next, "name", "PROV_RSA_SCHANNEL")
         case in_crypto.PROV_DSS_DH
            ldwc_type.SetItem(ll_next, "name", "PROV_DSS_DH")
         case in_crypto.PROV_DH_SCHANNEL
            ldwc_type.SetItem(ll_next, "name", "PROV_DH_SCHANNEL")
         case in_crypto.PROV_RSA_AES
            ldwc_type.SetItem(ll_next, "name", "PROV_RSA_AES")
         case else
            ldwc_type.SetItem(ll_next, "name", &
                  "Unknown Provider " + String(lul_ProvType[ll_idx]))
      end choose
   End If
   // add to Provider dropdown
   ls_find = "id = " + String(lul_ProvID[ll_idx])
   ll_find = ldwc_provider.Find(ls_find, 1, ldwc_provider.RowCount())
   If ll_find = 0 Then
      ll_next = ldwc_provider.InsertRow(0)
      ldwc_provider.SetItem(ll_next, "id", lul_ProvID[ll_idx])
      ldwc_provider.SetItem(ll_next, "typeid", lul_ProvType[ll_idx])
      ldwc_provider.SetItem(ll_next, "name", ls_Provider[ll_idx])
   End If
Next

ldwc_type.Sort()
ldwc_provider.Sort()

dw_main.SetItem(1, "type_id", in_crypto.iProviderType)
ldwo_type = dw_main.Object.type_id
dw_main.Event itemchanged(1, ldwo_type, String(in_crypto.iProviderType))

end subroutine

on w_main.create
this.cb_random=create cb_random
this.st_random=create st_random
this.sle_random=create sle_random
this.st_encrypt_label=create st_encrypt_label
this.cb_encrypt=create cb_encrypt
this.cb_decrypt=create cb_decrypt
this.st_encrypted_label=create st_encrypted_label
this.sle_source=create sle_source
this.sle_encrypted=create sle_encrypted
this.sle_hashvalue=create sle_hashvalue
this.st_hashvalue=create st_hashvalue
this.cb_hash=create cb_hash
this.sle_hashresult=create sle_hashresult
this.st_hashresult=create st_hashresult
this.dw_main=create dw_main
this.cb_cancel=create cb_cancel
this.Control[]={this.cb_random,&
this.st_random,&
this.sle_random,&
this.st_encrypt_label,&
this.cb_encrypt,&
this.cb_decrypt,&
this.st_encrypted_label,&
this.sle_source,&
this.sle_encrypted,&
this.sle_hashvalue,&
this.st_hashvalue,&
this.cb_hash,&
this.sle_hashresult,&
this.st_hashresult,&
this.dw_main,&
this.cb_cancel}
end on

on w_main.destroy
destroy(this.cb_random)
destroy(this.st_random)
destroy(this.sle_random)
destroy(this.st_encrypt_label)
destroy(this.cb_encrypt)
destroy(this.cb_decrypt)
destroy(this.st_encrypted_label)
destroy(this.sle_source)
destroy(this.sle_encrypted)
destroy(this.sle_hashvalue)
destroy(this.st_hashvalue)
destroy(this.cb_hash)
destroy(this.sle_hashresult)
destroy(this.st_hashresult)
destroy(this.dw_main)
destroy(this.cb_cancel)
end on

event open;// update settings
in_crypto.iProviderType     = in_crypto.PROV_RSA_FULL
in_crypto.iCryptoProvider   = in_crypto.of_GetDefaultProvider()
in_crypto.iEncryptAlgorithm = in_crypto.CALG_RC4
in_crypto.iHashAlgorithm    = in_crypto.CALG_MD5

// populate DataWindow dropdowns
wf_Populate()

end event

type cb_random from commandbutton within w_main
integer x = 951
integer y = 1132
integer width = 480
integer height = 100
integer taborder = 50
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Random Number"
end type

event clicked;ULong lul_random

lul_random = in_crypto.of_Random()

sle_random.text = String(lul_random)

end event

type st_random from statictext within w_main
integer x = 96
integer y = 1080
integer width = 635
integer height = 64
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Random Number Result:"
boolean focusrectangle = false
end type

type sle_random from singlelineedit within w_main
integer x = 96
integer y = 1144
integer width = 786
integer height = 76
integer taborder = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
boolean displayonly = true
borderstyle borderstyle = stylelowered!
end type

type st_encrypt_label from statictext within w_main
integer x = 96
integer y = 332
integer width = 443
integer height = 64
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Value to Encrypt:"
boolean focusrectangle = false
end type

type cb_encrypt from commandbutton within w_main
integer x = 1829
integer y = 384
integer width = 334
integer height = 100
integer taborder = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Encrypt"
end type

event clicked;SetPointer(HourGlass!)

If sle_source.text = "" Then
   MessageBox("Edit Error", "Value to Encrypt is required!")
   Return
End If

sle_encrypted.text = in_crypto.of_Encrypt(sle_source.text, "SecretKey")

end event

type cb_decrypt from commandbutton within w_main
integer x = 1829
integer y = 544
integer width = 334
integer height = 100
integer taborder = 70
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Decrypt"
end type

event clicked;String ls_decrypted

SetPointer(HourGlass!)

If sle_encrypted.text = "" Then
   MessageBox("Edit Error", "Encrypted Value is required!")
   Return
End If

ls_decrypted = in_crypto.of_Decrypt(sle_encrypted.text, "SecretKey")

MessageBox("The decrypted value is:", ls_decrypted)

end event

type st_encrypted_label from statictext within w_main
integer x = 96
integer y = 492
integer width = 443
integer height = 64
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Encrypted Value:"
boolean focusrectangle = false
end type

type sle_source from singlelineedit within w_main
integer x = 96
integer y = 396
integer width = 1664
integer height = 76
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
string text = "Powerbuilder Rules!"
borderstyle borderstyle = stylelowered!
end type

type sle_encrypted from singlelineedit within w_main
integer x = 96
integer y = 556
integer width = 1664
integer height = 76
integer taborder = 30
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
boolean displayonly = true
borderstyle borderstyle = stylelowered!
end type

type sle_hashvalue from singlelineedit within w_main
integer x = 96
integer y = 768
integer width = 1664
integer height = 76
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
string text = "Powerbuilder Rules!"
borderstyle borderstyle = stylelowered!
end type

type st_hashvalue from statictext within w_main
integer x = 96
integer y = 704
integer width = 443
integer height = 64
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Value to Hash:"
boolean focusrectangle = false
end type

type cb_hash from commandbutton within w_main
integer x = 1829
integer y = 756
integer width = 334
integer height = 100
integer taborder = 80
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Hash"
end type

event clicked;SetPointer(HourGlass!)

If sle_hashvalue.text = "" Then
   MessageBox("Edit Error", "Value to Hash is required!")
   Return
End If

sle_hashresult.text = in_crypto.of_GetHashValue(sle_hashvalue.text)

end event

type sle_hashresult from singlelineedit within w_main
integer x = 96
integer y = 928
integer width = 1664
integer height = 76
integer taborder = 50
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
boolean displayonly = true
borderstyle borderstyle = stylelowered!
end type

type st_hashresult from statictext within w_main
integer x = 96
integer y = 864
integer width = 443
integer height = 64
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Hash Result:"
boolean focusrectangle = false
end type

type dw_main from datawindow within w_main
integer x = 73
integer y = 64
integer width = 2089
integer height = 228
integer taborder = 10
string title = "none"
string dataobject = "d_main"
boolean border = false
boolean livescroll = true
end type

event constructor;this.InsertRow(0)

end event

event itemchanged;DataWindowChild ldwc_provider
String ls_filter, ls_provider, ls_find
Long ll_find, ll_Provider, ll_row

this.GetChild("provider_id", ldwc_provider)

choose case dwo.Name
   case "type_id"
      ls_filter = "typeid = " + data
      ldwc_provider.SetFilter(ls_filter)
      ldwc_provider.Filter()
      ldwc_provider.Sort()

      // set the ProviderType
      in_crypto.iProviderType = Long(data)

      // set the CryptoProvider
      ls_provider = in_crypto.of_GetDefaultProvider()
      in_crypto.iCryptoProvider = ls_provider

      // set Provider dropdown
      ls_find = "name = '" + ls_provider + "'"
      ll_find = ldwc_provider.Find(ls_find, 1, ldwc_provider.RowCount())
      If ll_find > 0 Then
         ll_Provider = ldwc_provider.GetItemNumber(ll_find, "id")
      Else
         SetNull(ll_Provider)
      End If
      this.SetItem(1, "provider_id", ll_Provider)
   case "provider_id"
      ll_row = ldwc_provider.GetRow()

      // set the CryptoProvider
      ls_provider = ldwc_provider.GetItemString(ll_row, "name")
      in_crypto.iCryptoProvider = ls_provider
end choose

sle_encrypted.text = ""
sle_hashresult.text = ""

end event

type cb_cancel from commandbutton within w_main
integer x = 2341
integer y = 1152
integer width = 334
integer height = 100
integer taborder = 90
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Cancel"
boolean cancel = true
end type

event clicked;Close(Parent)

end event