Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert u8 array to base64 string in Rust

I have an array of u8 in Rust. How would I go about converting these to a String representing them as base64?

like image 460
Newbyte Avatar asked Sep 22 '19 17:09

Newbyte


1 Answers

What you're looking for is the base64 crate, particularly its encode() function. Usage is pretty straightforward:

extern crate base64;

fn main() {
    let data: Vec<u8> = vec![1,2,3,4,5];
    println!("{}", base64::encode(&data))
}
like image 117
Sébastien Renauld Avatar answered Nov 14 '22 18:11

Sébastien Renauld