I would like to convert Hex value to Base64 String, I found one function in PB 2021 to convert but unfortunatlly it is input the Hex value as string so it converting from String to Base64 Not from Hex to Base64.
Any help to do that.
Thank you
I would like to convert Hex value to Base64 String, I found one function in PB 2021 to convert but unfortunatlly it is input the Hex value as string so it converting from String to Base64 Not from Hex to Base64.
Any help to do that.
Thank you
Your initial Hex string is already encoded, so if you want to get the same result as in Javascript, you first have to decode it:
//the (correct format) from Javascript Hex encoding to Base64:
//AQpCYXNlbVN0b3JlAg8zMDA2MDA5NjU0MDAwMzMDEzExLzI5LzIwMjEgMTU6MDE6MzYEBTg2LjI1BQUxMS4yNQ==
String ls_Base64Str, ls_HexStr, ls_decoded
blob lblb_data
CoderObject lnv_CoderObject1
lnv_CoderObject1 = Create CoderObject
ls_HexStr = "010A426173656D53746F7265020F333030363030393635343030303333031331312F32392F323032312031353A30313A3336040538362E3235050531312E3235"
// you first have to decode the hex encoded string:
//ls_decoded = string(lnv_CoderObject1.HexDecode(ls_hexstr), encodingutf8!)
//lblb_data = Blob(ls_decoded, encodingutf8!)
// or ... (as pointed out by René, you can do it in one go):
lblb_data = lnv_CoderObject1.HexDecode(ls_hexstr)
// now encode as Base64:
ls_Base64Str = lnv_CoderObject1.Base64Encode(lblb_data)
destroy lnv_CoderObject1
regards
you are correct, now it is coming correct as required
appreciate your precious help
Miguel Leeuwe you are correct, now it is coming correct as required
appreciate your precious help
Hello,
I presume that the Hex value is hex-encoded. In that case
1. HexDecode -> to convert the hex value to blob
2. base64encode -> to convert the resultant blob to base64encode
HTH
to make it more clear:
input value (Hex):
010A426173656D53746F7265020F333030363030393635343030303333031331312F32392F323032312031353A30313A3336040538362E3235050531312E3235
if I encode it by PB2021 function I will get: (Wrong format)
MDEwYTQyNjE3MzY1NmQ1Mzc0NmY3MjY1MDIwZjMzMzAzMDM2MzAzMDM5MzYzNTM0MzAzMDMwMzMzMzAzMTMzMTMxMmYzMjM5MmYzMjMwMzIzMTIwMzEzNTNhMzAzMTNhMzMzNjA0MDUzODM2MmUzMjM1MDUwNTMxMzEyZTMyMzU=
the (correct format) from Javascript Hex encoding to Base64:
AQpCYXNlbVN0b3JlAg8zMDA2MDA5NjU0MDAwMzMDEzExLzI5LzIwMjEgMTU6MDE6MzYEBTg2LjI1BQUxMS4yNQ==
the script in PB2021
String ls_Base64Str, ls_IV_Value
lblb_data = Blob(Lower(ls_HexStr), EncodingUTF8!)
CoderObject lnv_CoderObject1
lnv_CoderObject1 = Create CoderObject
ls_Base64Str = lnv_CoderObject1.Base64Encode(lblb_data)
If I look at the example in PB help it suggests it would be Ansi encoded?
Blob lblb_data
String ls_HexStr
CoderObject lnv_CoderObject
lnv_CoderObject = Create CoderObject
// ls_HexStr = lnv_CoderObject.HexEncode(Blob("Test Hex", EncodingANSI!))
ls_HexStr = "5465737420486578"
lblb_data = lnv_CoderObject.HexDecode(ls_HexStr)
messagebox("HexDecode", string(lblb_data, EncodingANSI!))
For HexDecode function it doesn't matter what the Hex value was before. It could also be that it was some binary.
So you can't say what encoding is the result blob. Or you may say: It is the same encoding it was used before. ;-)