特易招,招聘小程序
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.

28 lines
870 B

4 months ago
  1. import Crypto from '@/utils/oss-upload/common/crypto/crypto.js.js';
  2. (function() {
  3. // Shortcut
  4. var util = Crypto.util;
  5. Crypto.HMAC = function(hasher, message, key, options) {
  6. // Allow arbitrary length keys
  7. key = key.length > hasher._blocksize * 4 ?
  8. hasher(key, {
  9. asBytes: true
  10. }) :
  11. util.stringToBytes(key);
  12. // XOR keys with pad constants
  13. var okey = key,
  14. ikey = key.slice(0);
  15. for (var i = 0; i < hasher._blocksize * 4; i++) {
  16. okey[i] ^= 0x5C;
  17. ikey[i] ^= 0x36;
  18. }
  19. var hmacbytes = hasher(util.bytesToString(okey) +
  20. hasher(util.bytesToString(ikey) + message, {
  21. asString: true
  22. }), {
  23. asBytes: true
  24. });
  25. return options && options.asBytes ? hmacbytes :
  26. options && options.asString ? util.bytesToString(hmacbytes) :
  27. util.bytesToHex(hmacbytes);
  28. };
  29. })();