encode base64 rust
To encode a string to base64 in Rust, you can use the base64
crate. First, add the base64
crate to your Cargo.toml
file:
[dependencies]
base64 = "0.13.0"
Then, in your Rust code, you can use the encode
function from the base64
crate to encode a string to base64. Here's an example:
use base64;
fn main() {
let input = "Hello, World!";
let encoded = base64::encode(input);
println!("Encoded: {}", encoded);
}
This code will encode the string "Hello, World!" to base64 and print the encoded result. You can replace the input
variable with the string you want to encode.