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

35 行
984 B

  1. export function stringToArrayBuffer(s: string) {
  2. const base64String = unescape(encodeURIComponent(s));
  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. export function arrayBufferToHex(arrayBuffer: Iterable<number>) {
  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. export function getAlgorithm(algorithm: string) {
  19. const algorithms: { [k: string]: string } = {
  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. const lowercaseAlgorithm = algorithm.toLowerCase();
  28. if (lowercaseAlgorithm in algorithms) {
  29. return algorithms[lowercaseAlgorithm];
  30. }
  31. return "SHA-256";
  32. }