在常用的nodejs+express工程中,为了安全在登录及表单传输时,应该都需进行加密传输,目前个人常用到的加密方式有下列几种:
1、Hash算法加密:
创建一个nodejs文件hash.js,输入内容如下:
1 var crypto = require('crypto'); //加载crypto库 2 console.log(crypto.getHashes()); //打印支持的hash算法
结果如下:
1 [ 'DSA', 2 'DSA-SHA', 3 'DSA-SHA1', 4 'DSA-SHA1-old', 5 'RSA-MD4', 6 'RSA-MD5', 7 'RSA-MDC2', 8 'RSA-RIPEMD160', 9 'RSA-SHA', 10 'RSA-SHA1', 11 'RSA-SHA1-2', 12 'RSA-SHA224', 13 'RSA-SHA256', 14 'RSA-SHA384', 15 'RSA-SHA512', 16 'dsaEncryption', 17 'dsaWithSHA', 18 'dsaWithSHA1', 19 'dss1', 20 'ecdsa-with-SHA1', 21 'md4', 22 'md4WithRSAEncryption', 23 'md5', 24 'md5WithRSAEncryption', 25 'mdc2', 26 'mdc2WithRSA', 27 'ripemd', 28 'ripemd160', 29 'ripemd160WithRSA', 30 'rmd160', 31 'sha', 32 'sha1', 33 'sha1WithRSAEncryption', 34 'sha224', 35 'sha224WithRSAEncryption', 36 'sha256', 37 'sha256WithRSAEncryption', 38 'sha384', 39 'sha384WithRSAEncryption', 40 'sha512', 41 'sha512WithRSAEncryption', 42 'shaWithRSAEncryption', 43 'ssl2-md5', 44 'ssl3-md5', 45 'ssl3-sha1', 46 'whirlpool' ]