File: w_main.srw
Size: 20283
Date: Sun, 03 Feb 2019 16:23:28 +0100
$PBExportHeader$w_main.srw
forward
global type w_main from window
end type
type cb_encrypt_b64 from commandbutton within w_main
end type
type cb_hmac_b64 from commandbutton within w_main
end type
type cb_hash_b64 from commandbutton within w_main
end type
type st_5 from statictext within w_main
end type
type cbx_hexencrypt from checkbox within w_main
end type
type ddlb_encrypt_algorithm from dropdownlistbox within w_main
end type
type st_6 from statictext within w_main
end type
type cb_encrypt from commandbutton within w_main
end type
type ddlb_hash_algorithm from dropdownlistbox within w_main
end type
type st_4 from statictext within w_main
end type
type cb_hash from commandbutton within w_main
end type
type cb_hmac from commandbutton within w_main
end type
type sle_result from singlelineedit within w_main
end type
type st_3 from statictext within w_main
end type
type sle_password from singlelineedit within w_main
end type
type st_2 from statictext within w_main
end type
type sle_message from singlelineedit within w_main
end type
type st_1 from statictext within w_main
end type
type cb_cancel from commandbutton within w_main
end type
type cb_currentgmt from commandbutton within w_main
end type
type cb_hashfile from commandbutton within w_main
end type
type cb_random from commandbutton within w_main
end type
type cb_base64 from commandbutton within w_main
end type
end forward

global type w_main from window
integer width = 3013
integer height = 1048
boolean titlebar = true
string title = "Microsoft CryptoAPI"
boolean controlmenu = true
long backcolor = 67108864
string icon = "UserObject5!"
boolean center = true
cb_encrypt_b64 cb_encrypt_b64
cb_hmac_b64 cb_hmac_b64
cb_hash_b64 cb_hash_b64
st_5 st_5
cbx_hexencrypt cbx_hexencrypt
ddlb_encrypt_algorithm ddlb_encrypt_algorithm
st_6 st_6
cb_encrypt cb_encrypt
ddlb_hash_algorithm ddlb_hash_algorithm
st_4 st_4
cb_hash cb_hash
cb_hmac cb_hmac
sle_result sle_result
st_3 st_3
sle_password sle_password
st_2 st_2
sle_message sle_message
st_1 st_1
cb_cancel cb_cancel
cb_currentgmt cb_currentgmt
cb_hashfile cb_hashfile
cb_random cb_random
cb_base64 cb_base64
end type
global w_main w_main

type prototypes

end prototypes

type variables
n_cryptoapi in_capi

end variables

on w_main.create
this.cb_encrypt_b64=create cb_encrypt_b64
this.cb_hmac_b64=create cb_hmac_b64
this.cb_hash_b64=create cb_hash_b64
this.st_5=create st_5
this.cbx_hexencrypt=create cbx_hexencrypt
this.ddlb_encrypt_algorithm=create ddlb_encrypt_algorithm
this.st_6=create st_6
this.cb_encrypt=create cb_encrypt
this.ddlb_hash_algorithm=create ddlb_hash_algorithm
this.st_4=create st_4
this.cb_hash=create cb_hash
this.cb_hmac=create cb_hmac
this.sle_result=create sle_result
this.st_3=create st_3
this.sle_password=create sle_password
this.st_2=create st_2
this.sle_message=create sle_message
this.st_1=create st_1
this.cb_cancel=create cb_cancel
this.cb_currentgmt=create cb_currentgmt
this.cb_hashfile=create cb_hashfile
this.cb_random=create cb_random
this.cb_base64=create cb_base64
this.Control[]={this.cb_encrypt_b64,&
this.cb_hmac_b64,&
this.cb_hash_b64,&
this.st_5,&
this.cbx_hexencrypt,&
this.ddlb_encrypt_algorithm,&
this.st_6,&
this.cb_encrypt,&
this.ddlb_hash_algorithm,&
this.st_4,&
this.cb_hash,&
this.cb_hmac,&
this.sle_result,&
this.st_3,&
this.sle_password,&
this.st_2,&
this.sle_message,&
this.st_1,&
this.cb_cancel,&
this.cb_currentgmt,&
this.cb_hashfile,&
this.cb_random,&
this.cb_base64}
end on

on w_main.destroy
destroy(this.cb_encrypt_b64)
destroy(this.cb_hmac_b64)
destroy(this.cb_hash_b64)
destroy(this.st_5)
destroy(this.cbx_hexencrypt)
destroy(this.ddlb_encrypt_algorithm)
destroy(this.st_6)
destroy(this.cb_encrypt)
destroy(this.ddlb_hash_algorithm)
destroy(this.st_4)
destroy(this.cb_hash)
destroy(this.cb_hmac)
destroy(this.sle_result)
destroy(this.st_3)
destroy(this.sle_password)
destroy(this.st_2)
destroy(this.sle_message)
destroy(this.st_1)
destroy(this.cb_cancel)
destroy(this.cb_currentgmt)
destroy(this.cb_hashfile)
destroy(this.cb_random)
destroy(this.cb_base64)
end on

event open;ddlb_hash_algorithm.SelectItem(1)
ddlb_encrypt_algorithm.SelectItem(1)

end event

type cb_encrypt_b64 from commandbutton within w_main
integer x = 1975
integer y = 640
integer width = 407
integer height = 100
integer taborder = 100
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "Encrypt / B64"
end type

event clicked;String ls_Algorithm, ls_Message, ls_Password
String ls_Encrypted, ls_Result

If sle_message.text = "" Then
   MessageBox("Edit Error", "Message is required!")
   Return
End If

If sle_password.text = "" Then
   MessageBox("Edit Error", "Password is required!")
   Return
End If

ls_Algorithm = ddlb_encrypt_algorithm.text
ls_Message   = sle_message.text
ls_Password  = sle_password.text

If cbx_hexencrypt.Checked Then
   ls_Encrypted = in_capi.of_EncryptHex(ls_Algorithm, ls_Message, ls_Password)
Else
   ls_Encrypted = in_capi.of_Encrypt(ls_Algorithm, ls_Message, ls_Password)
End If
If IsNull(ls_Encrypted) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

// convert to base64
ls_Result = in_capi.of_Encode64(ls_Encrypted)
If IsNull(ls_Result) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

sle_result.text = ls_Result

end event

type cb_hmac_b64 from commandbutton within w_main
integer x = 1499
integer y = 800
integer width = 407
integer height = 100
integer taborder = 140
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "HMAC / B64"
end type

event clicked;Blob lblb_Message
String ls_Message, ls_Password
String ls_Algorithm, ls_HmacResult, ls_Result

ls_Message = sle_message.text
If ls_Message = "" Then
   MessageBox("Edit Error", "The message is required!", StopSign!)
   Return
End If

ls_Password = sle_password.text
If ls_Password = "" Then
   MessageBox("Edit Error", "The password is required!", StopSign!)
   Return
End If

ls_Algorithm = ddlb_hash_algorithm.text

ls_HmacResult = in_capi.of_Hmac(ls_Algorithm, ls_Message, ls_Password)
If IsNull(ls_HmacResult) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

// convert to base64
ls_Result = in_capi.of_Encode64(ls_HmacResult)
If IsNull(ls_Result) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

sle_result.text = ls_Result

end event

type cb_hash_b64 from commandbutton within w_main
integer x = 1499
integer y = 640
integer width = 407
integer height = 100
integer taborder = 90
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "Hash / B64"
end type

event clicked;Blob lblb_Message
String ls_Message, ls_Algorithm, ls_HashResult, ls_Result

ls_Message = sle_message.text
If ls_Message = "" Then
   MessageBox("Edit Error", "The message is required!", StopSign!)
   Return
End If

ls_Algorithm = ddlb_hash_algorithm.text

// not using the Ansi/Unicode option
lblb_Message  = Blob(ls_Message, EncodingAnsi!)

// generate hash
ls_HashResult = in_capi.of_Hash(ls_Algorithm, lblb_Message)
If IsNull(ls_HashResult) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

// convert to base64
ls_Result = in_capi.of_Encode64(ls_HashResult)
If IsNull(ls_Result) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

sle_result.text = ls_Result

end event

type st_5 from statictext within w_main
integer x = 2231
integer y = 212
integer width = 626
integer height = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
long backcolor = 67108864
string text = "(Used by HMAC / Encrypt)"
boolean focusrectangle = false
end type

type cbx_hexencrypt from checkbox within w_main
integer x = 1829
integer y = 504
integer width = 443
integer height = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
long backcolor = 67108864
string text = "Encrypt to Hex"
end type

type ddlb_encrypt_algorithm from dropdownlistbox within w_main
integer x = 1390
integer y = 488
integer width = 334
integer height = 540
integer taborder = 50
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
boolean sorted = false
boolean vscrollbar = true
string item[] = {"AES128","AES256","DES","RC2","RC4","3DES","3DES_112"}
borderstyle borderstyle = stylelowered!
end type

type st_6 from statictext within w_main
integer x = 896
integer y = 504
integer width = 462
integer height = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
long backcolor = 67108864
string text = "Encrypt Algorithm:"
alignment alignment = right!
boolean focusrectangle = false
end type

type cb_encrypt from commandbutton within w_main
integer x = 1024
integer y = 640
integer width = 407
integer height = 100
integer taborder = 80
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "Encrypt"
end type

event clicked;String ls_Algorithm, ls_Message, ls_Password
String ls_Encrypted, ls_Decrypted

If sle_message.text = "" Then
   MessageBox("Edit Error", "Message is required!")
   Return
End If

If sle_password.text = "" Then
   MessageBox("Edit Error", "Password is required!")
   Return
End If

ls_Algorithm = ddlb_encrypt_algorithm.text
ls_Message   = sle_message.text
ls_Password  = sle_password.text

If cbx_hexencrypt.Checked Then
   ls_Encrypted = in_capi.of_EncryptHex(ls_Algorithm, ls_Message, ls_Password)
Else
   ls_Encrypted = in_capi.of_Encrypt(ls_Algorithm, ls_Message, ls_Password)
End If
If IsNull(ls_Encrypted) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

sle_result.text = ls_Encrypted

If cbx_hexencrypt.Checked Then
   ls_Decrypted = in_capi.of_DecryptHex(ls_Algorithm, ls_Encrypted, ls_Password)
Else
   ls_Decrypted = in_capi.of_Decrypt(ls_Algorithm, ls_Encrypted, ls_Password)
End If
If IsNull(ls_Decrypted) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

If ls_Decrypted <> ls_Message Then
   MessageBox(this.Text, "Decryption Doesn't Match Original!")
End If

end event

type ddlb_hash_algorithm from dropdownlistbox within w_main
integer x = 475
integer y = 488
integer width = 334
integer height = 540
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
boolean sorted = false
boolean vscrollbar = true
string item[] = {"SHA1","SHA256","SHA384","SHA512","MD2","MD5"}
borderstyle borderstyle = stylelowered!
end type

type st_4 from statictext within w_main
integer x = 73
integer y = 504
integer width = 402
integer height = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
long backcolor = 67108864
string text = "Hash Algorithm:"
boolean focusrectangle = false
end type

type cb_hash from commandbutton within w_main
integer x = 73
integer y = 640
integer width = 407
integer height = 100
integer taborder = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "Hash"
end type

event clicked;String ls_Algorithm, ls_Message, ls_Result

If sle_message.text = "" Then
   MessageBox("Edit Error", "Message is required!")
   Return
End If

ls_Algorithm = ddlb_hash_algorithm.text
ls_Message   = sle_message.text

ls_Result = in_capi.of_Hash(ls_Algorithm, ls_Message)
If IsNull(ls_Result) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

sle_result.text = ls_Result

end event

type cb_hmac from commandbutton within w_main
integer x = 549
integer y = 640
integer width = 407
integer height = 100
integer taborder = 70
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "HMAC"
end type

event clicked;String ls_Algorithm, ls_Message, ls_Password, ls_Result

If sle_message.text = "" Then
   MessageBox("Edit Error", "Message is required!")
   Return
End If

If sle_password.text = "" Then
   MessageBox("Edit Error", "Password is required!")
   Return
End If

ls_Algorithm = ddlb_hash_algorithm.text
ls_Message   = sle_message.text
ls_Password  = sle_password.text

ls_Result = in_capi.of_Hmac(ls_Algorithm, ls_Message, ls_Password)
If IsNull(ls_Result) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

sle_result.text = ls_Result

end event

type sle_result from singlelineedit within w_main
integer x = 366
integer y = 328
integer width = 2565
integer height = 84
integer taborder = 30
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
boolean displayonly = true
borderstyle borderstyle = stylelowered!
end type

type st_3 from statictext within w_main
integer x = 73
integer y = 340
integer width = 187
integer height = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
long backcolor = 67108864
string text = "Result:"
boolean focusrectangle = false
end type

type sle_password from singlelineedit within w_main
integer x = 366
integer y = 200
integer width = 1687
integer height = 84
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
string text = "SecretPassword"
borderstyle borderstyle = stylelowered!
end type

type st_2 from statictext within w_main
integer x = 73
integer y = 212
integer width = 265
integer height = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
long backcolor = 67108864
string text = "Password:"
boolean focusrectangle = false
end type

type sle_message from singlelineedit within w_main
integer x = 366
integer y = 72
integer width = 2565
integer height = 84
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
string text = "PowerBuilder Rules!"
borderstyle borderstyle = stylelowered!
end type

type st_1 from statictext within w_main
integer x = 73
integer y = 84
integer width = 247
integer height = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
long textcolor = 33554432
long backcolor = 67108864
string text = "Message:"
boolean focusrectangle = false
end type

type cb_cancel from commandbutton within w_main
integer x = 2450
integer y = 800
integer width = 407
integer height = 100
integer taborder = 160
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "Cancel"
boolean cancel = true
end type

event clicked;Close(Parent)

end event

type cb_currentgmt from commandbutton within w_main
integer x = 1975
integer y = 800
integer width = 407
integer height = 100
integer taborder = 150
boolean bringtotop = true
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "GMT/UTC"
end type

event clicked;DateTime ldt_current
Integer li_offset
String ls_datetime

ldt_current = in_capi.of_CurrentUTC()

ls_datetime = String(ldt_current, &
               "ddd, dd mmm yyyy hh:mm:ss") + " GMT"

MessageBox( this.text, &
            "The current time is: " + ls_datetime)

end event

type cb_hashfile from commandbutton within w_main
integer x = 549
integer y = 800
integer width = 407
integer height = 100
integer taborder = 120
boolean bringtotop = true
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "Hash a File"
end type

event clicked;String ls_pathname, ls_filename, ls_Algorithm, ls_result
Integer li_rc

sle_result.text = ""

li_rc = GetFileOpenName("Select a File", ls_pathname, ls_filename)
If li_rc = 1 Then
   ls_Algorithm = ddlb_hash_algorithm.text
   ls_result = in_capi.of_HashFile(ls_Algorithm, ls_pathname)
   If IsNull(ls_result) Then
      MessageBox(in_capi.LastFunction + " Failed", &
            in_capi.LastErrText, StopSign!)
      Return
   End If
   sle_result.text = ls_result
End If

end event

type cb_random from commandbutton within w_main
integer x = 73
integer y = 800
integer width = 407
integer height = 100
integer taborder = 110
boolean bringtotop = true
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "Random Nbr"
end type

event clicked;ULong lul_Random

lul_Random = in_capi.of_RandomNbr()
If IsNull(lul_Random) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

sle_result.text = String(lul_Random)

end event

type cb_base64 from commandbutton within w_main
integer x = 1024
integer y = 800
integer width = 407
integer height = 100
integer taborder = 130
boolean bringtotop = true
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Segoe UI"
string text = "Base64"
end type

event clicked;String ls_message, ls_result

If sle_message.text = "" Then
   MessageBox("Edit Error", "Message is required!")
   Return
End If

ls_message = sle_message.text

ls_result = in_capi.of_Encode64(ls_message)
If IsNull(ls_Result) Then
   MessageBox(in_capi.LastFunction + " Failed", &
         in_capi.LastErrText, StopSign!)
   Return
End If

sle_result.text = ls_Result

end event

  • window w_main(srw)
    • commandbutton cb_encrypt_b64
    • commandbutton cb_hmac_b64
    • commandbutton cb_hash_b64
    • statictext st_5
    • checkbox cbx_hexencrypt
    • dropdownlistbox ddlb_encrypt_algorithm
    • statictext st_6
    • commandbutton cb_encrypt
    • dropdownlistbox ddlb_hash_algorithm
    • statictext st_4
    • commandbutton cb_hash
    • commandbutton cb_hmac
    • singlelineedit sle_result
    • statictext st_3
    • singlelineedit sle_password
    • statictext st_2
    • singlelineedit sle_message
    • statictext st_1
    • commandbutton cb_cancel
    • commandbutton cb_currentgmt
    • commandbutton cb_hashfile
    • commandbutton cb_random
    • commandbutton cb_base64