您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536
  1. function stringToArrayBuffer(string) {
  2. const base64String = unescape(encodeURIComponent(string));
  3. const charList = base64String.split("");
  4. const arrayBuffer = [];
  5. for (let i = 0; i < charList.length; i += 1) {
  6. arrayBuffer.push(charList[i].charCodeAt(0));
  7. }
  8. return new Uint8Array(arrayBuffer);
  9. }
  10. function arrayBufferToHex(arrayBuffer) {
  11. const byteArray = new Uint8Array(arrayBuffer);
  12. let str = "";
  13. for (let i = 0; i < byteArray.byteLength; i += 1) {
  14. str += byteArray[i].toString(16).padStart(2, "0");
  15. }
  16. return str;
  17. }
  18. function getAlgorithm(algorithm) {
  19. const algorithms = {
  20. sha1: "SHA-1",
  21. "sha-1": "SHA-1",
  22. sha256: "SHA-256",
  23. "sha-256": "SHA-256",
  24. sha512: "SHA-512",
  25. "sha-512": "SHA-512",
  26. };
  27. return algorithms[algorithm.toLowerCase()];
  28. }
  29. module.exports = {
  30. stringToArrayBuffer,
  31. arrayBufferToHex,
  32. getAlgorithm,
  33. };