稳定性: 2 - 稳定

    crypto 模块提供了加密功能,包括对 OpenSSL 的哈希、HMAC、加密、解密、签名、以及验证功能的一整套封装。

    使用 require('crypto') 来访问该模块。

    1. const crypto = require('crypto');
    2. const secret = 'abcdefg';
    3. const hash = crypto.createHmac('sha256', secret)
    4. .update('I love cupcakes')
    5. .digest('hex');
    6. console.log(hash);
    7. // 打印:
    8. // c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e