Skip to content

base64_encode

Encodes data as base64 (RFC 4648 section 4), with = padding.

use helpers4::hex::base64_encode;

Cargo feature hex (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features hex

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.7", default-features = false, features = ["hex"] }
pub fn base64_encode(data: &[u8]) -> String
ParameterTypeDescription
data&[u8]The bytes to encode.

String — The base64 string; its length is always a multiple of 4.

use helpers4::hex::base64_encode;

assert_eq!(base64_encode(b"any carnal pleas"), "YW55IGNhcm5hbCBwbGVhcw==");
assert_eq!(base64_encode(b""), "");

src/hex/base64_encode.rs