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.

25 lines
576 B

4 years ago
  1. 'use strict';
  2. var crypto = require('crypto');
  3. function md5(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('md5').update(bytes).digest();
  20. }
  21. module.exports = md5;