Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const crypto = require('crypto');

const getWSSE = ({ username, password, nonce, created }) => {

  const Created = new Date().toISOString();
  const rawNonce = nonce || Created + '-' + Math.random().toString();
  const NonceB64 = Buffer.from(rawNonce).toString('base64');

  let passwordSha1 = crypto.createHash('sha1').update(password).digest('hex');

  let textBuff = Buffer.concat([
    Buffer.from(NonceB64, 'utf8'),
    Buffer.from(Created, 'utf8'),
    Buffer.from(passwordSha1, 'hex'),
  ]);

  let pwHash = crypto.createHash('sha1').update(textBuff).digest('binary');

  const PasswordDigest = Buffer.from(pwHash, 'binary').toString('base64');

  // free mem-leak
  passwordSha1 = null;
  textBuff = null;
  pwHash = null;

  return {
    Username: username,
    Password: PasswordDigest,
    RawNonce: rawNonce,
    NonceB64: NonceB64,
    CreatedAt: Created
  };
};


var token = getWSSE({ username: 'bob', password: 'taadtaadpstcsm' });
console.log(token)

node v9.7.1 linux/amd64