Win-Base64 API
Description
A simple wrapper over the Windows API Base64 Encoding and Decoding
- String to Base64 (
encode) - Base64 to String (
decode)
Sample Code
use decode;
use encode;
let text = "What's up?😊🥘🍲🚩🏁🚀👌😁👍😍❤️💕🎶";
let base64_string = encode?;
let decoded_text = decode?;
// If it worked, text and decoded_text would be the same
println!;
println!;
OUTPUT
Original: What's up?😊👌😁👍😍❤️💕🎶
Decoded: What's up?😊👌😁👍😍❤️💕🎶
Yes this supports Emojis.
Similar code to base64 library
let a = "hello world";
let b = "aGVsbG8gd29ybGQ=";
assert_eq!;
assert_eq!;
Multiple Decodes
-
Decode as
&mut [u8](decode_as_mut8)
Probably the fastest
But the sizes are to be specified manually.
So probably the riskiest as well.let text = "What's up?"; let base64_string = encode?; let mut decoded_arr = vec!; use decode_as_mut8; decode_as_mut8?; // If it worked, text and decoded_text would be the same println!; println!; -
Decode as
Vec<u8>(decode_as_vecu8)
Allocates a vec of the correct size Returns this vec with decoded values Safer than mut u8 as it knows the decoded sizelet text = "What's up?"; let base64_string = encode?; use decode_as_vecu8; let decoded_vec = decode_as_vecu8?; // If it worked, text and decoded_text would be the same println!; println!; -
Decode as String (
decode)
Present in top most exampleuse decode; use encode; let text = "What's up?😊🥘🍲🚩🏁🚀👌😁👍😍❤️💕🎶"; let base64_string = encode?; let decoded_text = decode?; // If it worked, text and decoded_text would be the same println!; println!;