Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. return this.getMessages().pipe(
  2. map(msgs =>{
  3. return msgs.map(message => {
  4.  
  5. function fromHexString(buffer: string) {
  6. return new Uint8Array(buffer.match(/[\da-f]{2}/gi).map(function (h) {
  7. return parseInt(h, 16)
  8. }))
  9. }
  10.  
  11. let encryptedAesKey = message.substring(0, 512);
  12. let msgToDecrypt = message.substring(512);
  13. var returnString: string;
  14.  
  15. return window.crypto.subtle.importKey(
  16. "pkcs8",
  17. fromHexString(this.currentUserValue.encodedPrivateKey), //binaryDer,
  18. {
  19. name: "RSA-OAEP",
  20. hash: "SHA-256",
  21. },
  22. true,
  23. ["decrypt"]
  24. ).then(rsaKey => {
  25. console.log("1");
  26. return window.crypto.subtle.decrypt({
  27. name: "RSA-OAEP",
  28. },
  29. rsaKey,
  30. fromHexString(encryptedAesKey)
  31. )
  32. })
  33. .then(decrypted => {
  34. console.log("2");
  35. return window.crypto.subtle.importKey(
  36. "raw",
  37. decrypted,
  38. "AES-GCM",
  39. true,
  40. ["encrypt", "decrypt"]
  41. )
  42. })
  43. .then(aesKey => {
  44. console.log("3");
  45. return window.crypto.subtle.decrypt({
  46. name: "AES-GCM",
  47. iv: new Uint8Array([155, 57, 251, 30, 54, 130, 195, 47, 193, 142, 136, 156]),
  48. tagLength: 128,
  49. },
  50. aesKey,
  51. fromHexString(msgToDecrypt)
  52. )
  53. })
  54. .then(it => {
  55. console.log("4");
  56. var enc = new TextDecoder("utf-8");
  57. //console.log(enc.decode(it));
  58. returnString = enc.decode(it) as string;
  59. return enc.decode(it) as string
  60. });
  61. })}
  62. )
  63. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement