You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sha1.js 579B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var crypto = require('crypto');
  3. function sha1(bytes) {
  4. if (typeof Buffer.from === 'function') {
  5. // Modern Buffer API
  6. if (Array.isArray(bytes)) {
  7. bytes = Buffer.from(bytes);
  8. } else if (typeof bytes === 'string') {
  9. bytes = Buffer.from(bytes, 'utf8');
  10. }
  11. } else {
  12. // Pre-v4 Buffer API
  13. if (Array.isArray(bytes)) {
  14. bytes = new Buffer(bytes);
  15. } else if (typeof bytes === 'string') {
  16. bytes = new Buffer(bytes, 'utf8');
  17. }
  18. }
  19. return crypto.createHash('sha1').update(bytes).digest();
  20. }
  21. module.exports = sha1;