0
Votes
Undo
  1. aymen moawad
  2. PowerBuilder
  3. Thursday, 3 March 2022 02:08 AM UTC

hello

i am using powerbuilder 10.5 .

can anyone help with encode hex to base64 . 

aymen moawad Accepted Answer Pending Moderation
  1. Friday, 4 March 2022 07:44 AM UTC
  2. PowerBuilder
  3. # 1

Dear John 

 

what i am working with is Arabic characters , your string list is only English characters . 

Comment
  1. John Fauss
  2. Friday, 4 March 2022 14:06 PM UTC
You made no mention of mapping to Arabic in your original post, so this is understandable. I'm sure there are alternative encoding map lists/tables available on the web that will permit you to adapt the code as needed.
  1. Helpful
There are no comments made yet.
aymen moawad Accepted Answer Pending Moderation
  1. Friday, 4 March 2022 07:42 AM UTC
  2. PowerBuilder
  3. # 2

Dear Rene

if you go to https://cryptii.com/ 

 

the encoding of :

0115426f627320426173656d656e74205265636f726473020f3130303032353930363730303030330314323032322d30342d32355431353a33303a30305a040a323130303130302e393905093331353031352e3135

is :

ARVCb2JzIEJhc2VtZW50IFJlY29yZHMCDzEwMDAyNTkwNjcwMDAwMwMUMjAyMi0wNC0yNVQxNTozMDowMFoECjIxMDAxMDAuOTkFCTMxNTAxNS4xNQ==

 

while windows Crypt32.dll ( the one you posted ) gives :

 

MDExNTQyNmY2MjczMjA0MjYxNzA2NTZkNjU2ZTc0MjA1MjY1NjM2ZjcyNjQ3MzAyMGYzMTMwMzAzMDMyMzUzOTMwMzYzNzMwMzAzMDMwMzMwMzE0MzIzMDMyMmQzMDM0MmQ

 

and the  correct one is the one in dark blue ( cryptii.com )

Comment
  1. René Ullrich
  2. Friday, 4 March 2022 08:09 AM UTC
If you use the blob function as in my example it converts a string to a blob. If you use cryptii.com and enter your value as string you will also get the MDE... encoded value.

You have to convert your hex value(s) in a different way to blob. With newer Powerbuilder versions this is easy. With 12.5 you have to write your own conversion. (maybe this helps you: https://groups.google.com/g/sybase.public.powerbuilder.powerscript/c/DccN01w4dyQ )
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 3 March 2022 16:56 PM UTC
  2. PowerBuilder
  3. # 3

[Edit: Replaced function source code with improved version that uses fewer variables and memory.]

Here's a script for a PowerBuilder function I created that performs Base64 encoding that should be compatible with PB 10:

// Public Function: of_Base64Encode(String as_Input) returns String

Constant String BASE64_ENCODING_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Blob    lblob_input
Byte    lbyte_char
Integer li_rc, li_six_bit_value[4]
Long    ll_accumulator, ll_index, ll_blob_length
String  ls_encoded_token, ls_output

// Check for null or empty argument string.
If IsNull(as_input) Then
   SetNull(ls_output)
   Return ls_output
End If
If Len(as_input) = 0 Then Return ""

// Place the input string into a Blob as a series of UTF-8 characters.
// The base64 encoding process encodes thres bytes (characters) of the blob at a time,
// because three bytes = 24 bits, which is evenly divisible by six (bits), producing
// an encoded token of four characters.
lblob_input = Blob(as_input,EncodingUTF8!)
ll_blob_length = Len(lblob_input)

// Encode the blob, up to three bytes (24 bits) at a time.
ls_output = ""
For ll_index = 1 To ll_blob_length Step 3
   
   // Accumulate the next three UTF-8 characters (24 bits) into a Long,
   // then separate the bit pattern into four six-bit values.
   li_rc = GetByte(lblob_input,ll_index,lbyte_char)
   
   ll_accumulator = lbyte_char * 256
   
   If ll_index+1 <= ll_blob_length Then
      li_rc = GetByte(lblob_input,ll_index+1,lbyte_char)
      ll_accumulator += lbyte_char
   End If
   
   ll_accumulator *= 256
   
   If ll_index+2 <= ll_blob_length Then
      li_rc = GetByte(lblob_input,ll_index+2,lbyte_char)
      ll_accumulator += lbyte_char
   End If
   
   // The low-order 24 bits of the Long now contain the next three UTF-8 characters.
   // Split these 24 bits into four six-bit values.
   li_six_bit_value[4] = Mod(ll_accumulator,64)
   ll_accumulator /= 64
   li_six_bit_value[3] = Mod(ll_accumulator,64)
   ll_accumulator /= 64
   li_six_bit_value[2] = Mod(ll_accumulator,64)
   li_six_bit_value[1] = ll_accumulator / 64
   
   // Map the four six-bit values into the base64 encoding map.
   // If needed, "padding" values are translated into equal signs (=).
   ls_encoded_token = Mid(BASE64_ENCODING_MAP,li_six_bit_value[1]+1,1) + &
                      Mid(BASE64_ENCODING_MAP,li_six_bit_value[2]+1,1)
   If ll_index+1 <= ll_blob_length Then
      // Two chars (16 bits) are represented by three six-bit values.
      ls_encoded_token += Mid(BASE64_ENCODING_MAP,li_six_bit_value[3]+1,1)
   Else
      // There was only one character, so append a "pad" encoding character.
      ls_encoded_token += "="
   End If
   If ll_index+2 <= ll_blob_length Then
      // Three chars (all 24 bits) are represented by all four six-bit values.
      ls_encoded_token += Mid(BASE64_ENCODING_MAP,li_six_bit_value[4]+1,1)
   Else
      // There were only one or two characters, so append a "pad" encoding character.
      ls_encoded_token += "="
   End If
   
   // Append the Base64-encoded token onto the output string, and repeat.
   ls_output += ls_encoded_token
   
Next

// Done!
Return ls_output

HTH, John

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 3 March 2022 07:29 AM UTC
  2. PowerBuilder
  3. # 4

You can use the Microsoft API function CryptBinaryToStringW.

Function Boolean CryptBinaryToString ( &
blob pbBinary, &
ulong cbBinary, &
ulong dwFlags, &
Ref string pszString, &
Ref ulong pcchString) Library "Crypt32.dll" Alias For "CryptBinaryToStringW"



CONSTANT ulong CRYPT_STRING_BASE64 = 1
CONSTANT ulong CRYPT_STRING_NOCRLF = 1073741824 // 0x40000000 - not for windows XP!
uLong 	lul_buflen
Blob 	lblob_value
string 	ls_base64

lblob_value = blob ("your blob here")
ls_base64 = Space (2 + 1.5 * (Len (lblob_value) + 2))
lul_buflen = Len (ls_base64)
If Not CryptBinaryToString (lblob_value, Len (lblob_value), CRYPT_STRING_BASE64 + CRYPT_STRING_NOCRLF, ls_base64, lul_buflen) Then
   // error
End If

MessageBox ("", ls_base64)

 

 

Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Thursday, 3 March 2022 07:10 AM UTC
  2. PowerBuilder
  3. # 5

Aymen

Have you checked Chilkat (https://www.example-code.com/powerbuilder/default.asp)?  They have lot of activeX, may be there one which you need.  Those (all) are not free though.

Happiness Always
BKR Sivaprakash

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 3 March 2022 04:50 AM UTC
  2. PowerBuilder
  3. # 6

Hi, Aymen - 

I suggest you download and check out the CryptoAPI free code example at Roland Smith's TopWizProgramming web site:

https://topwizprogramming.com/freecode_cryptoapi.html

All of the free code samples are provided in both PB 10.5 and PB 12.6 (and higher) versions. Let me know how that works out for you.

Regards, John

Comment
There are no comments made yet.
aymen moawad Accepted Answer Pending Moderation
  1. Thursday, 3 March 2022 03:25 AM UTC
  2. PowerBuilder
  3. # 7

hello john 

 

yes i want to encode utf-8 hex string to base64 string . data is about 200 character more or less .

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 3 March 2022 03:13 AM UTC
  2. PowerBuilder
  3. # 8

A little more information, please.

Hex in what form? Binary (in a Blob variable) or in a String ("ff018c47", for example)? How much data? Are you wanting to produce a character string that contains the base64-encoded equivalent?

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.