Giter Site home page Giter Site logo

sha digest can contain NUL bytes about bcrypt HOT 5 CLOSED

pyca avatar pyca commented on July 21, 2024
sha digest can contain NUL bytes

from bcrypt.

Comments (5)

reaperhulk avatar reaperhulk commented on July 21, 2024

Very good catch (and apologies for taking so long on responding to this!). The digest needs to be encoded to prevent null bytes, but doing something like encoding a 64 byte SHA512 hash will exceed the limit so either you accept some limited truncation there or switch to a shorter hash function. I'll put in a PR to update the docs on this front.

from bcrypt.

alex avatar alex commented on July 21, 2024

Hex sha256 is a good compromise IMO
On Nov 29, 2015 12:41 PM, "Paul Kehrer" [email protected] wrote:

Very good catch (and apologies for taking so long on responding to this!).
The digest needs to be encoded to prevent null bytes, but doing something
like encoding a 64 byte SHA512 hash will exceed the limit so either you
accept some limited truncation there or switch to a shorter hash function.
I'll put in a PR to update the docs on this front.


Reply to this email directly or view it on GitHub
#55 (comment).

from bcrypt.

hyperknot avatar hyperknot commented on July 21, 2024

In the meantime I've reviewed this issue, and the solution for me was to use the passlib wrapper for bcrypt. passlib has a well tested built-in method called: bcrypt_sha256
https://pythonhosted.org/passlib/lib/passlib.hash.bcrypt_sha256.html

Implementation line:
b64encode(sha256(secret).digest())
https://bitbucket.org/ecollins/passlib/src/fa26802fc88fbc6b2d4b9676970bed7e6d53fc9d/passlib/handlers/bcrypt.py?at=default&fileviewer=file-view-default#bcrypt.py-677

from bcrypt.

reaperhulk avatar reaperhulk commented on July 21, 2024

#57 addresses this.

from bcrypt.

reaperhulk avatar reaperhulk commented on July 21, 2024

This appears to be resolved so I'll close this now. If there's still an issue feel free to reopen.

from bcrypt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.