Does node.js have built-in base64 encoding yet?
The reason why I ask this is that
crypto can only output hex, binary or ascii data. For example:
var cipher = crypto.createCipheriv('des-ede3-cbc', encryption_key, iv);var ciph = cipher.update(plaintext, 'utf8', 'hex');ciph += cipher.final('hex');var decipher = crypto.createDecipheriv('des-ede3-cbc', encryption_key, iv);var txt = decipher.update(ciph, 'hex', 'utf8');txt += decipher.final('utf8');
According to the docs,
update() can output base64-encoded data. However,
final() doesn't support base64. I tried and it will break.
If I do this:
var ciph = cipher.update(plaintext, 'utf8', 'base64'); ciph += cipher.final('hex');
Then what should I use for decryption? Hex or base64?
Therefore, I'm looking for a function to base64-encode my encrypted hex output.
Base64 encode can be achieved by
$ echo Some_data_to_be_converted | base64U29tZV9kYXRhX3RvX2JlIF9jb252ZXJ0ZWQK
And Base64 decode can be achieved by
$ echo U29tZV9kYXRhX3RvX2JlIF9jb252ZXJ0ZWQK | base64 -dSome_data_to_be_converted
How to achieve Base64URL encode/decode?
Is it just enough to replace "+" with "-" and "/" with " _" ?
When to do the padding "#"(adding/remove "#" to be considered )?
There's a way to encode/decode a string to/from Base64 without having the padding at the end? I mean the '==' ending.
base64.URLEncoding.EncodeToString to encode and it works perfectly but I didn't see a way to decide to not use the padding at the end ( like on java ).
I´m using a .NET core 3.0 project on Windows 10. I´m trying to encode a string to base64 with below code:
var stringvalue = "Row1" + Environment.NewLine + "\n\n" + "Row2";var encodedString = Convert.ToBase64String(Encoding.UTF8.GetBytes(stringvalue));
encodedString has then below result:
However, if I´m passing the same value to this site (https://www.base64encode.org/), i´m getting another result:
I want the string to be encoded as how it´s done in https://www.base64encode.org. Any ideas how to get this done?
I want to achieve Base64 URL safe encoding in C#. In Java, we have the common
Codec library which gives me an URL safe encoded string. How can I achieve the same using C#?
byte toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes("StringToEncode");string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
The above code converts it to Base64, but it pads
==. Is there is way to achieve URL safe encoding?