base58.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto 2 // Copyright (c) 2009-2022 The Bitcoin Core developers 3 // Distributed under the MIT software license, see the accompanying 4 // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 6 /** 7 * Why base-58 instead of standard base-64 encoding? 8 * - Don't want 0OIl characters that look the same in some fonts and 9 * could be used to create visually identical looking data. 10 * - A string with non-alphanumeric characters is not as easily accepted as input. 11 * - E-mail usually won't line-break if there's no punctuation to break at. 12 * - Double-clicking selects the whole string as one word if it's all alphanumeric. 13 */ 14 #ifndef BITCOIN_BASE58_H 15 #define BITCOIN_BASE58_H 16 17 #include <span.h> 18 19 #include <string> 20 #include <vector> 21 22 /** 23 * Encode a byte span as a base58-encoded string 24 */ 25 std::string EncodeBase58(Span<const unsigned char> input); 26 27 /** 28 * Decode a base58-encoded string (str) into a byte vector (vchRet). 29 * return true if decoding is successful. 30 */ 31 [[nodiscard]] bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len); 32 33 /** 34 * Encode a byte span into a base58-encoded string, including checksum 35 */ 36 std::string EncodeBase58Check(Span<const unsigned char> input); 37 38 /** 39 * Decode a base58-encoded string (str) that includes a checksum into a byte 40 * vector (vchRet), return true if decoding is successful 41 */ 42 [[nodiscard]] bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len); 43 44 #endif // BITCOIN_BASE58_H