Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return this.getMessages().pipe(
- map(msgs =>{
- return msgs.map(message => {
- function fromHexString(buffer: string) {
- return new Uint8Array(buffer.match(/[\da-f]{2}/gi).map(function (h) {
- return parseInt(h, 16)
- }))
- }
- let encryptedAesKey = message.substring(0, 512);
- let msgToDecrypt = message.substring(512);
- var returnString: string;
- return window.crypto.subtle.importKey(
- "pkcs8",
- fromHexString(this.currentUserValue.encodedPrivateKey), //binaryDer,
- {
- name: "RSA-OAEP",
- hash: "SHA-256",
- },
- true,
- ["decrypt"]
- ).then(rsaKey => {
- console.log("1");
- return window.crypto.subtle.decrypt({
- name: "RSA-OAEP",
- },
- rsaKey,
- fromHexString(encryptedAesKey)
- )
- })
- .then(decrypted => {
- console.log("2");
- return window.crypto.subtle.importKey(
- "raw",
- decrypted,
- "AES-GCM",
- true,
- ["encrypt", "decrypt"]
- )
- })
- .then(aesKey => {
- console.log("3");
- return window.crypto.subtle.decrypt({
- name: "AES-GCM",
- iv: new Uint8Array([155, 57, 251, 30, 54, 130, 195, 47, 193, 142, 136, 156]),
- tagLength: 128,
- },
- aesKey,
- fromHexString(msgToDecrypt)
- )
- })
- .then(it => {
- console.log("4");
- var enc = new TextDecoder("utf-8");
- //console.log(enc.decode(it));
- returnString = enc.decode(it) as string;
- return enc.decode(it) as string
- });
- })}
- )
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement