Has anyone used the crypt module lately ?
I’m trying to encode a string as below, but the function returns me some strange characters.
pass = “xzyttafs”;
pass=crypt.hash_sha1(pass)
print('sha1: ’ … pass)
Has anyone used the crypt module lately ?
I’m trying to encode a string as below, but the function returns me some strange characters.
pass = “xzyttafs”;
pass=crypt.hash_sha1(pass)
print('sha1: ’ … pass)
Unfortunately the crypt extension is not well documented, but I would suspect the hash_sha1
is not for encryption, but for calculating hash, so the results “seems” correct.
More on sha1 hash function can be read on wikipedia for example..
Those hash functions are one directional, so you can’t encode them, but there are bi directional operations (XOR being the foundation). But I’m not an expert in cybersecurity and this is only my shallow understanding, I might be wrong.
Thanks for the explanation.
I am looking for the equivalent of the following PHP function
<?php
$text = 'Hello';
$digest = hash('sha256', $text);
echo $digest;
The result is an array of bytes, with values in the range [0…255].
That’s not a printable range, so you’re bound to get some garbled output if you print the string as-is.
To make it “nice looking”, you probably want to convert each byte into a hex value.
E.g. like this
Thank you. You guys are awesome !