The following piece of code runs successfully on a python 2 machine:
base64_str = base64.encodestring('%s:%s' % (username,password)).replace('\n', '')
I am trying to port it over to Python 3 but when I do so I encounter the following error:
>>> a = base64.encodestring('{0}:{1}'.format(username,password)).replace('\n','')Traceback (most recent call last): File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 519, in _input_type_check m = memoryview(s)TypeError: memoryview: str object does not have the buffer interfaceThe above exception was the direct cause of the following exception:Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 548, in encodestring return encodebytes(s) File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 536, in encodebytes _input_type_check(s) File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 522, in _input_type_check raise TypeError(msg) from errTypeError: expected bytes-like object, not str
I tried searching examples for encodestring usage but not able to find a good document. Am I missing something obvious? I am running this on RHEL 2.6.18-371.11.1.el5
Does node.js have built-in base64 encoding yet?
The reason why I ask this is that final()
from 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.
I'm using 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:
Um93MQ0KCgpSb3cy
stringvalue is:
Row1\r\n\n\nRow2
However, if I´m passing the same value to this site (https://www.base64encode.org/), i´m getting another result:
Um93MVxyXG5cblxuUm93Mg==
In visual studio, I tried to resave the file with Unix lineendings, but without any luck:
I want the string to be encoded as how it´s done in https://www.base64encode.org. Any ideas how to get this done?
Casa - Mapa del lloc - Intimitat - Enllaços - Copyright © 2019 Cortex IT Ltd : Contacte : admin @ cortexit.co.uk
Please note that by viewing our site you agree to our use of cookies (see Intimitat for details). You will only see this message once.