Convert Base 10 to Base 64

  • Hi All

    I am working with a encryption project, i got stuck with a conversion, i need to convert a Base 10 decimal number to a Base64, for Example if i use 123 (Base 10), the output must be B7, has any one came across this problem, please let me know how can i do this on SQL server 2005

    Thanks in advance 🙂

  • I'm confused. Do you mean number base 64 or Base64 Text Encoding. The text encoding method will pad to a 4-byte boundary so the result should be B7==. That looks like an excuse to do a CLR routine to me - as C# has all the classes to do encoding - but then I'm fond of CLR functions at the moment 😀

    Number base 64 of 123 decimal would be 1(64) and the character for 59(the remainder) lets assume your base64 character set is A..Z then a...z then 0-9 as your first 62 characters, then char 59 is '6' so the result is '16'

    I don't know if its been done but it looks like a good challange to do it in T-SQL

    I think you'd have a map string of the character set, link to a tally table (to get the position), do your numeric conversion by recursivly dividing by powers of 64 and looking up the remainder in the map string.

    I remember doing something like that in COBOL many years ago. :w00t:

  • Or this http://www.sqlservercentral.com/scripts/Miscellaneous/31520/ could be what you're looking for

  • Thanks Tom, i am looking for the first one B7==, As you said you can do this on C#, but i am just wondering if there are any other ways we can do this on SQL 🙂

  • you can try this free online service to convert base10 string to base64 online.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply