cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

HEX to String

Former Member
0 Likes
933

Hi all,

I need to convert a HEX to string for X509 certificate serial number. Anyone have a simple function for this.

Right now I'm using MS SQL Server to do the conversion but would love to do it client side.

SELECT CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), '0x3030303031303030303030323031303633393638', 1))


I'm using PB 12.5.1

Regards,

Adrian

View Entire Topic
Former Member
0 Likes

When dealing with some certificate data I've used an of_hextobyte method to convert hex data to a byte.  You could adapt that.  Just call in it a loop stepping through your string two characters at a time.  Think I may have borrowed this from PFC, but not sure.

char    lch_char[]

integer  li_byte

int li_dec[48 to 70], li_i, li_len

//Get the decimal code for hexadecimal value of '0' to 'F'

// Whose ASC Value are from 48 to 57 and 65 to 70

For li_i = 48 To 57

  li_dec[li_i] = li_i - 48

Next

For li_i = 65 To 70

  li_dec[li_i] = li_i - 55

Next

as_hex = upper(as_hex)

lch_char = as_hex

li_len = len (as_hex)

//Convert Hexadecimal data into decimal

For li_i = 1 to li_len

  //Make sure only 0's through f's are present

  Choose Case lch_char[li_i]

    Case '0' to '9', 'A' to 'F'

      li_byte = li_byte * 16 + li_dec[asc(lch_char[li_i])]

    Case Else

      Return li_byte

  End Choose 

Next

Return li_byte