1

Can anyone help me to implement Base58 encoding stored procedure in PostgreSQL.

I've found answer for numbers but I'm looking for similar stored procedure that can accept TEXT or VARCHAR value.

Community
  • 1
  • 1
tefozi
  • 5,390
  • 5
  • 38
  • 52

1 Answers1

1

On this very rare occasion I'm going to suggest you don't do this. It will be computationally possible but highly inadvisable.

https://en.wikipedia.org/wiki/Base58

In contrast to Base64, the digits of the encoding don't line up well with byte boundaries of the original data. For this reason, the method is well-suited to encode large integers, but not designed to encode longer portions of binary data.

To put this another way, Base58 is not designed to encode strings / text. Your main alternatives are:

  • Base64 which if copied manually by a human, the human may make mistakes. Otherwise Base64 is safe to copy / paste
  • Hexadecimal which is easily copied by humans but significantly longer than Base64

If you feel you really need Base58 and not Base64 then it may be worth editing your requirements into your question. This may help someone give an answer more specific to your requiremnts:

  • What are these strings you need to convert (examples are preferable)?
  • Why do they need to be Base58 and not Base64 (what other system are you passing these to)?
Philip Couling
  • 13,581
  • 5
  • 53
  • 85