/core/src/main/php/security/checksum/MD5.class.php

http://github.com/xp-framework/xp-framework · PHP · 47 lines · 14 code · 5 blank · 28 comment · 0 complexity · d4c2f674b285ae80b23252e52e1da339 MD5 · raw file

  1. <?php
  2. /* This class is part of the XP framework
  3. *
  4. * $Id$
  5. */
  6. uses('security.checksum.Checksum');
  7. /**
  8. * MD5 checksum
  9. *
  10. * @see xp://security.checksum.Checksum
  11. * @see php://md5
  12. * @purpose Provide an API to check MD5 checksums
  13. */
  14. class MD5 extends Checksum {
  15. /**
  16. * Create a new checksum from a string
  17. *
  18. * @param string str
  19. * @return security.checksum.MD5
  20. */
  21. public static function fromString($str) {
  22. return new MD5(md5($str));
  23. }
  24. /**
  25. * Returns message digest
  26. *
  27. * @return security.checksum.MessageDigestImpl
  28. */
  29. public static function digest() {
  30. return MessageDigest::newInstance('md5');
  31. }
  32. /**
  33. * Create a new checksum from a file object
  34. *
  35. * @param io.File file
  36. * @return security.checksum.MD5
  37. */
  38. public static function fromFile($file) {
  39. return new MD5(md5_file($file->uri));
  40. }
  41. }
  42. ?>