How to use the pvtsutils.Convert.ToUtf8String function in pvtsutils

To help you get started, we’ve selected a few pvtsutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PeculiarVentures / 2key-ratchet / test / ratchet.ts View on Github external
const BobRatchet = await AsymmetricRatchet.create(BobID, AlicePreKeyBundle);
                const BobMessage1 = await BobRatchet.encrypt(Convert.FromUtf8String(messageText));
                const BobMessage2 = await BobRatchet.encrypt(Convert.FromUtf8String(messageText));

                // Only first message mast be PreKeyMessage
                assert.isTrue(BobMessage1 instanceof PreKeyMessageProtocol);
                assert.isTrue(BobMessage2 instanceof MessageSignedProtocol);

                const AliceRatchet = await AsymmetricRatchet.create(AliceID, BobMessage1 as PreKeyMessageProtocol);

                let decrypted = await AliceRatchet.decrypt((BobMessage1 as PreKeyMessageProtocol).signedMessage);
                assert.equal(messageText, Convert.ToUtf8String(decrypted));

                decrypted = await AliceRatchet.decrypt((BobMessage2 as MessageSignedProtocol));
                assert.equal(messageText, Convert.ToUtf8String(decrypted));
            });
github PeculiarVentures / 2key-ratchet / test / ratchet.ts View on Github external
const BobID = await createIdentity(2);
                const AlicePreKeyBundle = await createPreKeyBundle(AliceID);
                const messageText = "Hello world!!";

                const BobRatchet = await AsymmetricRatchet.create(BobID, AlicePreKeyBundle);
                const BobMessage1 = await BobRatchet.encrypt(Convert.FromUtf8String(messageText));
                const BobMessage2 = await BobRatchet.encrypt(Convert.FromUtf8String(messageText));

                // Only first message mast be PreKeyMessage
                assert.isTrue(BobMessage1 instanceof PreKeyMessageProtocol);
                assert.isTrue(BobMessage2 instanceof MessageSignedProtocol);

                const AliceRatchet = await AsymmetricRatchet.create(AliceID, BobMessage1 as PreKeyMessageProtocol);

                let decrypted = await AliceRatchet.decrypt((BobMessage1 as PreKeyMessageProtocol).signedMessage);
                assert.equal(messageText, Convert.ToUtf8String(decrypted));

                decrypted = await AliceRatchet.decrypt((BobMessage2 as MessageSignedProtocol));
                assert.equal(messageText, Convert.ToUtf8String(decrypted));
            });
github PeculiarVentures / webcrypto-liner / src / subtle.ts View on Github external
private fixNativeResult(method: SubtleMethods, args: any[], res: any): any {
    if (method === "exportKey") {
      if (args[0]?.toLowerCase?.() === "jwk" && res instanceof ArrayBuffer) {
        // IE11 uses ArrayBuffer instead of JSON object
        return JSON.parse(Convert.ToUtf8String(res));
      }
    }

    if (this.browserInfo.name === Browser.IE) {
      // wrap IE11 native key
      if ("privateKey" in res) {
        const privateKeyUsages = ["sign", "decrypt", "unwrapKey", "deriveKey", "deriveBits"];
        const publicKeyUsages = ["verify", "encrypt", "wrapKey"];
        return {
          privateKey: this.wrapNativeKey(res.privateKey, args[0], args[1], args[2].filter((o: string) => privateKeyUsages.includes(o))),
          publicKey: this.wrapNativeKey(res.publicKey, args[0], args[1], args[2].filter((o: string) => publicKeyUsages.includes(o))),
        };
      } else if ("extractable" in res) {
        return this.wrapNativeKey(res, method === "importKey" ? args[2] : args[4], res.extractable, method === "importKey" ? args[4] : args[6]);
      }
    }
github PeculiarVentures / webcrypto-liner / src / subtle.ts View on Github external
const data = await this.exportKey(args[0], args[1]);
        const keyData = (args[0] === "jwk") ? Convert.FromUtf8String(JSON.stringify(data)) : data;
        const res = await this.encrypt(args[3], args[2], keyData);
        return res;
      } catch (e) {
        Debug.warn(`Cannot wrap key by native functions. ${e.message}`, e);
      }
    }

    if (method === "unwrapKey") {
      try {
        Debug.info(`Trying to unwrap key by using native functions`, args);
        // unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages);
        // indexes     0          1            2               3                   4                 5           6
        const data = await this.decrypt(args[3], args[2], args[1]);
        const keyData = (args[0] === "jwk") ? JSON.parse(Convert.ToUtf8String(data)) : data;
        const res = await this.importKey(args[0], keyData, args[4], args[5], args[6]);
        return res;
      } catch (e) {
        Debug.warn(`Cannot unwrap key by native functions. ${e.message}`, e);
      }
    }

    if (method === "deriveKey") {
      try {
        Debug.info(`Trying to derive key by using native functions`, args);
        const data = await this.deriveBits(args[0], args[1], args[2].length);
        const res = await this.importKey("raw", data, args[2], args[3], args[4]);
        return res;
      } catch (e) {
        Debug.warn(`Cannot derive key by native functions. ${e.message}`, e);
      }
github PeculiarVentures / 2key-ratchet / examples / simple.js View on Github external
.then((bytes) => {
                                console.log("Bob's decrypted message:", Convert.ToUtf8String(bytes));
                            })
                    });
github PeculiarVentures / tsprotobuf / src / converter.ts View on Github external
public static async get(value: Uint8Array) {
        return Convert.ToUtf8String(value);
    }
}