hello
i am using powerbuilder 10.5 .
can anyone help with encode hex to base64 .
hello
i am using powerbuilder 10.5 .
can anyone help with encode hex to base64 .
Dear John
what i am working with is Arabic characters , your string list is only English characters .
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 )
[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
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)
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
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
hello john
yes i want to encode utf-8 hex string to base64 string . data is about 200 character more or less .
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?