Skip to content

Commit 4697cc6

Browse files
committed
-Buffer +strToBytes
1 parent 2ef88d5 commit 4697cc6

4 files changed

Lines changed: 62 additions & 42 deletions

File tree

bcrypt.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,20 @@
652652
}
653653
}
654654

655+
function _stringToBytes ( str ) {
656+
var ch, st, re = [];
657+
for (var i = 0; i < str.length; i++ ) {
658+
ch = str.charCodeAt(i);
659+
st = [];
660+
do {
661+
st.push( ch & 0xFF );
662+
ch = ch >> 8;
663+
} while (ch);
664+
re = re.concat( st.reverse() );
665+
}
666+
return re;
667+
}
668+
655669
/**
656670
* Internally hashes a string.
657671
* @param {string} s String to hash
@@ -689,12 +703,8 @@
689703
var real_salt = salt.substring(offset + 3, offset + 25);
690704
s += minor >= 'a' ? "\000" : "";
691705

692-
var buf = new Buffer(s); // TODO (dcode): What is this good for? Getting bytes?
693-
var passwordb = [];
706+
var passwordb = _stringToBytes(s);
694707
var saltb = [];
695-
for (var r=0; r<buf.length; r++) {
696-
passwordb.push(buf[r]);
697-
}
698708
saltb = base64.decode(real_salt, BCRYPT_SALT_LEN);
699709

700710
/**

0 commit comments

Comments
 (0)