Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

md5.js 576B

12345678910111213141516171819202122232425
  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;