PowerBuilder Base64 Encode/Decode With Key
Source Code
Local Function Declaration
1 2 |
Function Int b64_size(ULong size,ULong flag) Library "des64.dll" Alias For "b64_size;Ansi" Function Int b64_des(Ref String In,Ref String out,String Key,ULong size,ULong flag)Library "des64.dll" Alias For "b64_des;Ansi" |
Base64 Encode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Long ll_size String ls_result String as_Source, as_Key as_Key = "SecretKey" as_Source = "https://pblib.com/" If IsNull(as_Source) Or Trim(as_Source) = '' Or & IsNull(as_Key) Or Trim(as_Key) = '' Then Return End If Space(ll_size) ll_size = b64_size(Len(as_Source),1) ls_result = Space(ll_size) b64_des(as_Source,ls_result,as_Key,Len(as_Source),1) //Return ls_result |
Base64 Decode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Long ll_size String ls_result String as_Source, as_Key as_Key = "SecretKey" as_Source = "ZNEb4KJq8gJVD+OkRX0r+2h5xV7fGwN8QIbWuXv/bbLv9aUI3qTubQ==" If IsNull(as_Source) Or Trim(as_Source) = '' Or & IsNull(as_Key) Or Trim(as_Key) = '' Then Return End If Space(ll_size) ll_size = b64_size(Len(as_Source),0) ls_result = Space(ll_size) b64_des(as_Source,ls_result,as_Key,Len(as_Source),0) //Return ls_result |
Source Code Example
w_main from window
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 |
forward global type w_main from window end type type sle_key from singlelineedit within w_main end type type st_3 from statictext within w_main end type type st_2 from statictext within w_main end type type st_1 from statictext within w_main end type type mle_output from multilineedit within w_main end type type mle_input from multilineedit within w_main end type type cb_decode from commandbutton within w_main end type type cb_encode from commandbutton within w_main end type end forward global type w_main from window integer width = 2318 integer height = 1328 boolean titlebar = true string title = "PowerBuilder Base64 With Key" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true sle_key sle_key st_3 st_3 st_2 st_2 st_1 st_1 mle_output mle_output mle_input mle_input cb_decode cb_decode cb_encode cb_encode end type global w_main w_main type prototypes Function Int b64_size(ULong size,ULong flag) Library "des64.dll" Alias For "b64_size;Ansi" Function Int b64_des(Ref String In,Ref String out,String Key,ULong size,ULong flag)Library "des64.dll" Alias For "b64_des;Ansi" end prototypes forward prototypes public function string wf_encode (string as_source, string as_key) public function string wf_decode (string as_source, string as_key) end prototypes public function string wf_encode (string as_source, string as_key);//==================================================================== // Function: w_main.wf_encode() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_source // value string as_key //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/01/06 //-------------------------------------------------------------------- // Usage: w_main.wf_encode ( string as_source, string as_key ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long ll_size String ls_result If IsNull(as_Source) Or Trim(as_Source) = '' Or & IsNull(as_Key) Or Trim(as_Key) = '' Then Return '' End If Space(ll_size) ll_size = b64_size(Len(as_Source),1) ls_result = Space(ll_size) b64_des(as_Source,ls_result,as_Key,Len(as_Source),1) Return ls_result end function public function string wf_decode (string as_source, string as_key);//==================================================================== // Function: w_main.wf_decode() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_source // value string as_key //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2022/01/06 //-------------------------------------------------------------------- // Usage: w_main.wf_decode ( string as_source, string as_key ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long ll_size String ls_result If IsNull(as_Source) Or Trim(as_Source) = '' Or & IsNull(as_Key) Or Trim(as_Key) = '' Then Return '' End If Space(ll_size) ll_size = b64_size(Len(as_Source),0) ls_result = Space(ll_size) b64_des(as_Source,ls_result,as_Key,Len(as_Source),0) Return ls_result end function on w_main.create this.sle_key=create sle_key this.st_3=create st_3 this.st_2=create st_2 this.st_1=create st_1 this.mle_output=create mle_output this.mle_input=create mle_input this.cb_decode=create cb_decode this.cb_encode=create cb_encode this.Control[]={this.sle_key,& this.st_3,& this.st_2,& this.st_1,& this.mle_output,& this.mle_input,& this.cb_decode,& this.cb_encode} end on on w_main.destroy destroy(this.sle_key) destroy(this.st_3) destroy(this.st_2) destroy(this.st_1) destroy(this.mle_output) destroy(this.mle_input) destroy(this.cb_decode) destroy(this.cb_encode) end on type sle_key from singlelineedit within w_main integer x = 366 integer y = 32 integer width = 951 integer height = 96 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "SecretKey" borderstyle borderstyle = stylelowered! end type type st_3 from statictext within w_main integer x = 64 integer y = 696 integer width = 343 integer height = 76 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Output Text:" boolean focusrectangle = false end type type st_2 from statictext within w_main integer x = 64 integer y = 180 integer width = 329 integer height = 76 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Input Text:" boolean focusrectangle = false end type type st_1 from statictext within w_main integer x = 50 integer y = 44 integer width = 315 integer height = 76 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Secret Key:" boolean focusrectangle = false end type type mle_output from multilineedit within w_main integer x = 50 integer y = 784 integer width = 2167 integer height = 400 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type mle_input from multilineedit within w_main integer x = 50 integer y = 260 integer width = 2167 integer height = 400 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "https://pblib.com/" borderstyle borderstyle = stylelowered! end type type cb_decode from commandbutton within w_main integer x = 1664 integer y = 32 integer width = 297 integer height = 96 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Decode" end type event clicked;String ls_input, ls_key, ls_output ls_key = sle_key.Text ls_input = mle_input.Text ls_output = wf_decode(ls_input, ls_key) mle_output.Text = ls_output end event type cb_encode from commandbutton within w_main integer x = 1353 integer y = 32 integer width = 297 integer height = 96 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Encode" end type event clicked;String ls_input, ls_key, ls_output ls_key = sle_key.Text ls_input = mle_input.Text ls_output = wf_encode(ls_input, ls_key) mle_output.Text = ls_output end event |
Find Projects On Github click here
Good Luck!
how do you do it if the key is turned off
dear yoga
key must be correct encryption and decryption. In case you used a function with a key it is mandatory. if you don’t use key then you can learn des64.dll for this case. I checked it and it works fine. i don’t have time to test it about pb7. I think your pb version is too old. you can refer to pb10.5 which is a free key series version. you can use in version 12.6 or higher. You can completely upgrade your projects to versions higher than 2022. But from 2019R3 and above, you must install the runtime when deploying. so you can upgrade to 2019r2 to get new functions. and the compatible optimal faces will be higher. there are many better support functions.
thks!