Giter Site home page Giter Site logo

Comments (6)

pvorb avatar pvorb commented on August 26, 2024

Sorry, but I don't understand where this is an issue.

so that i'm not getting the result i'm expecting

Could you give me an example with the exact results you get and the ones you are expecting?

from node-md5.

salba avatar salba commented on August 26, 2024
var md5 = require('./../../lib/MD5/');

describe('test md5', function () {
    it('should produce binary', function () {
        var hash1, hash2, hash3
        hash1 = md5('abc', {asString: true});
        hash2 = md5(hash1 + 'a', {asString: true});
        hash3 = md5(hash1 + 'a');
        console.log('hash1', hash1);
        console.log('hash2', hash2);
        console.log('hash3', hash3);
        //current code using utf8 on message
        //output is:
        //hash1 �P�<ÒO°Ö�?}(ár
        //hash2 =ªÙmeÐñY��ìj^X-û
        //hash3 3daad96d65d0f159988fec6a5e582dfb

//expected output is: (since the hash1 is a string with binary encoding, hash2 and hash3 should honor that encoding)
        //hash1 �P�<ÒO°Ö�?}(ár
        //hash2 Å(OQä®Æ8Ái
        //hash3 131f0ac52813044f5110e4aec638c169
    });
});

from node-md5.

pvorb avatar pvorb commented on August 26, 2024

But hash1 + 'a' results in '�P�<ÒO°Ö�?}(ára', doesn't it? And that is hashed correctly.

I cannot change JavaScript's handling of strings.

from node-md5.

salba avatar salba commented on August 26, 2024

nope - for the current md5 module hash1 + 'a' results in "=ªÙmeÐñY��ìj^X-û" whereas below the hash1 + 'a' results in "Å(OQä®Æ8Ái". Basically, the current MD5 module does not give the option of using a binary encoded string in the message. It always processes the string as UTF8 but will output it as a binary string if you pass the option.asString=true. (Just seems inconsistent).

I'm hoping you can give an option as to what encoding to use for the string message.

Thanks.

Here's a sample code using node's basic crypto where I expect hash2 as "Å(OQä®Æ8Ái"

Code:

var crypto = require('crypto');

describe('test md5 crypto', function () {
    it('should produce binary', function () {
        var md5, hash1, hash2, hash3
        md5 = crypto.createHash('md5');
        md5.update('abc', 'binary');
        hash1 = md5.digest('binary');
        md5 = crypto.createHash('md5');
        md5.update(hash1 + 'a', 'binary');
        hash2 = md5.digest('binary');
        md5 = crypto.createHash('md5');
        md5.update(hash1 + 'a', 'binary');
        hash3 = md5.digest('hex');
        console.log('hash1', hash1);
        console.log('hash2', hash2);
        console.log('hash3', hash3);

        //hash1 �P�<ÒO°Ö�?}(ár
        //hash2 Å(OQä®Æ8Ái
        //hash3 131f0ac52813044f5110e4aec638c169
    });
});

from node-md5.

pvorb avatar pvorb commented on August 26, 2024

Okay, I get your point.

You can send me a pull request that implements this, if you really need such a feature in this module. Otherwise use crypto instead.

from node-md5.

pvorb avatar pvorb commented on August 26, 2024

resolved by #7

from node-md5.

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.