25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
876 B

  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. };