marshallpierce / rust-base64

base64, in rust
Apache License 2.0
617 stars 115 forks source link

How to generate the base64 format like openssl command #235

Closed RickSKy closed 1 year ago

RickSKy commented 1 year ago

'/usr/bin/openssl base64' can crate base64 string. And I try to use '/usr/bin/openssl base64 -d ' to decode the message which rust-base64 generated, but it failed. I have tried general_purpose::STANDARD_NO_PAD , URL_SAFE_NO_PAD, STANDARD, URL_SAFE. Thanks

marshallpierce commented 1 year ago

Can you be more specific about "it failed"?

RickSKy commented 1 year ago

rust to generate base64 text

fn main() {
    let hello = "hello";
    let encoded = general_purpose::STANDARD.encode(hello);
    std::fs::write("base64.txt", encoded).unwrap();
}

base64.txt data is "aGVsbG8=" then use openssl command to decode

$ /usr/bin/openssl base64 -in base64.txt -d -v -out data.txt
bufsize=8192
bytes read   :        8
bytes written:        0

the decoded data is none

marshallpierce commented 1 year ago

This is a problem with openssl base64, not this crate.

OpenSSL base64 subcommand produces nothing:

% echo -n 'aGVsbG8=' | openssl base64 -d

Top level base64:

% echo -n 'aGVsbG8=' | base64 -d
hello

Example CLI in this repo:

% echo -n 'aGVsbG8=' | cargo run --example base64 -- --decode
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/examples/base64 --decode`
hello