Encryption in nodejs

前端 未结 2 1360
死守一世寂寞
死守一世寂寞 2021-02-20 15:46

I\'m trying to port the following php code to javascript on node.js:

$mac = hash_hmac(\'SHA256\', \'string\', \'secret\', true);
$coded = base64_encode($mac);

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 16:21

    The method is called createHmac

    > Crypto = require('crypto');
    { Credentials: [Function: Credentials],
      createCredentials: [Function],
      Hash: [Function],
      createHash: [Function],
      Hmac: [Function],
      createHmac: [Function],
      Cipher: [Function],
      createCipher: [Function],
      createCipheriv: [Function],
      Decipher: [Function],
      createDecipher: [Function],
      createDecipheriv: [Function],
      Sign: [Function],
      createSign: [Function],
      Verify: [Function],
      createVerify: [Function],
      DiffieHellman: [Function],
      createDiffieHellman: [Function],
      pbkdf2: [Function],
      randomBytes: [Function],
      pseudoRandomBytes: [Function],
      rng: [Function],
      prng: [Function] }
    

提交回复
热议问题