1

This is regarding sha256Hash field in signer operation.

let hash = sha256.createHash('sha256').update(message).digest('hex');

Here the input parameter message should be 256 bit value. Assuming my input is less than 256 bit (say for example I want to pass "hello" as parameter), what are the possible ways of padding or encoding the data in secure way ?

0

1 Answer 1

1

Which sha256 implementation are you using? Both sha.js (bundled with JavaScript StellarSDK) and native node implementation do not require padding.

3
  • I'm guessing the "256 bit value" requirement comes from this answer: stellar.stackexchange.com/a/431/111
    – Synesso
    Mar 13, 2018 at 11:03
  • 1
    Bartek stated that "there are no restrictions on the value of x". So in case of openly available message one can just use sha256(x). If additional security required (i.e. protection from rainbow tables attack), then use symmetric encryption (for example, AES) before hashing - sha256(aes(x, 'my secret')). Even simple XOR cypher will do in this case.
    – Orbit Lens
    Mar 13, 2018 at 12:31
  • 1
    To clarify here for OP, SHA256 is a function that takes X as an input and has an output that is a 256 bit value no matter the size of the input. Check out this: passwordsgenerator.net/sha256-hash-generator Thus, you can, as stated above, use anything as x. In practice, as @OrbitLens stated, if you are implementing something like the Lightning Network where you want to use a secret X to unlock an account/transaction, you want to make sure X is not guessable. Ref: dev.lightning.community/overview/#multihop-payments
    – Rob
    Mar 13, 2018 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.