nalgeon / sqlean

The ultimate set of SQLite extensions
MIT License
3.72k stars 118 forks source link

Feature request: a Base32/64 (en/de)coder for 'crypto' #78

Closed veermans closed 1 year ago

veermans commented 1 year ago

Thanks for the very rich SQLite extension set!

It would be great to have a base32 (and base64) converter (encoding and decoding) with the 'crypto' extension as an alternative to the hex function for producing output of the SHA functions that is both readable and as compact as possible (rfc4648). The filename-safe alternative (64) and the extended-hex alternative (32) might also fit some use cases.

Best, Erwin

nalgeon commented 1 year ago

Working on it.

asg017 commented 1 year ago

btw in case you haven't seen, the SQLite team recently added these to their codebase, in case you want to adopt it

https://sqlite.org/src/file?name=ext/misc/base64.c

https://sqlite.org/src/file?name=ext/misc/base85.c

https://sqlite.org/src/file?name=ext/misc/basexx.c

nalgeon commented 1 year ago

Added encode and decode functions (similar to the ones in postgres) in 0.19.4:

select encode('hello', 'base32');
-- NBSWY3DP
select decode('NBSWY3DP', 'base32');
-- hello
select encode('hello', 'base64');
-- aGVsbG8=
select decode('aGVsbG8=', 'base64');
-- hello

@veermans please let me know if they fit your use cases.

veermans commented 1 year ago

Yes, works like a charm. Thanks!

nalgeon commented 1 year ago

Added three more algorithms — base85, hex and url — in 0.19.5. I think that's enough for now.