How to use the pvtsutils.Convert.FromUtf8String 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 / webcrypto-liner / test / aes.ts View on Github external
{
      // skip: browser.name === Browser.Edge,
      name: "AES-128-CTR",
      actions: {
        generateKey: [
          {
            algorithm: { name: "AES-CTR", length: 128 } as AesKeyGenParams,
            extractable: true,
            keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
          },
        ],
        encrypt: [
          {
            algorithm: {
              name: "AES-CTR",
              counter: Convert.FromUtf8String("1234567890abcdef"),
              length: 128,
            } as AesCtrParams,
            data: Convert.FromUtf8String("test message"),
            encData: Convert.FromHex("e1d561c49ce4eb2f448f8a00"),
            key: {
              format: "raw",
              data: Convert.FromUtf8String("1234567890abcdef"),
              algorithm: { name: "AES-CTR" },
              extractable: true,
              keyUsages: ["encrypt", "decrypt"],
            },
          },
        ],
        import: [
          {
            name: "raw",
github PeculiarVentures / webcrypto-liner / src / subtle.ts View on Github external
Debug.info(`Call native '${method}' method`, nativeArgs);
        const res = await nativeSubtle[method].apply(nativeSubtle, nativeArgs);

        return this.fixNativeResult(method, args, res);
      }
    } catch (e) {
      Debug.warn(`Error on native '${method}' calling. ${e.message}`, e);
    }

    if (method === "wrapKey") {
      try {
        Debug.info(`Trying to wrap key by using native functions`, args);
        // wrapKey(format, key, wrappingKey, wrapAlgorithm);
        // indexes    0     1        2             3
        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;
github PeculiarVentures / 2key-ratchet / examples / simple.js View on Github external
.then((BobCipher) => {
                        // Encrypt message for Alice
                        return BobCipher.encrypt(Convert.FromUtf8String("Hello Alice!!!"));
                    })
                    .then((proto) => {
github PeculiarVentures / webcrypto-liner / test / des.ts View on Github external
data: Convert.FromUtf8String("test message"),
            encData: Convert.FromHex("b9ef20e7db926490e4ff8680d99d2141"),
            key: {
              format: "raw" as KeyFormat,
              algorithm: { name: "DES-EDE3-CBC" },
              extractable: true,
              keyUsages: ["encrypt", "decrypt"] as KeyUsage[],
              data: Convert.FromUtf8String("1234567890abcdef12345678"),
            },
          },
        ],
        import: [
          {
            name: "raw",
            format: "raw" as KeyFormat,
            data: Convert.FromUtf8String("1234567890abcdef12345678"),
            algorithm: "DES-EDE3-CBC",
            extractable: true,
            keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"] as KeyUsage[],
          },
          {
            name: "wrong key size",
            error: true,
            format: "raw",
            data: Convert.FromUtf8String("12345678"),
            algorithm: "DES-EDE3-CBC",
            extractable: true,
            keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
          },
          {
            name: "jwk",
            format: "jwk",
github PeculiarVentures / webcrypto-liner / test / aes.ts View on Github external
data: Convert.FromUtf8String("test message"),
            encData: Convert.FromHex("d8eab579ed2418f41ca9c4567226f54cb391d3ca2cb6819dace35691"),
            key: {
              format: "raw",
              data: Convert.FromUtf8String("1234567890abcdef12345678"),
              algorithm: { name: "AES-GCM" },
              extractable: true,
              keyUsages: ["encrypt", "decrypt"],
            },
          },
        ],
        import: [
          {
            name: "raw",
            format: "raw",
            data: Convert.FromUtf8String("1234567890abcdef12345678"),
            algorithm: "AES-GCM",
            extractable: true,
            keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
          },
          {
            name: "jwk",
            format: "jwk",
            data: {
              kty: "oct",
              alg: "A192GCM",
              k: "MTIzNDU2Nzg5MGFiY2RlZjEyMzQ1Njc4",
              ext: true,
              key_ops: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
            },
            algorithm: "AES-GCM",
            extractable: true,
github PeculiarVentures / webcrypto-liner / test / des.ts View on Github external
},
        ],
        encrypt: [
          {
            algorithm: {
              name: "DES-CBC",
              iv: Convert.FromUtf8String("12345678"),
            } as core.DesParams,
            data: Convert.FromUtf8String("test message"),
            encData: Convert.FromHex("3af3f901ff01fe0102dfbbf37d9bdb94"),
            key: {
              format: "raw" as KeyFormat,
              algorithm: { name: "DES-CBC" },
              extractable: true,
              keyUsages: ["encrypt", "decrypt"] as KeyUsage[],
              data: Convert.FromUtf8String("12345678"),
            },
          },
        ],
        import: [
          {
            name: "raw",
            format: "raw" as KeyFormat,
            data: Convert.FromUtf8String("12345678"),
            algorithm: "DES-CBC",
            extractable: true,
            keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"] as KeyUsage[],
          },
          {
            name: "jwk",
            format: "jwk" as KeyFormat,
            data: {
github PeculiarVentures / webcrypto / test / aes.ts View on Github external
{
            algorithm: { name: "AES-ECB", length: 128 } as AesKeyGenParams,
            extractable: true,
            keyUsages: ["encrypt", "decrypt"] as KeyUsage[],
          },
        ],
        encrypt: [
          {
            algorithm: {
              name: "AES-ECB",
            } as Algorithm,
            data: Convert.FromUtf8String("test message"),
            encData: Convert.FromHex("c6ec2f91a9f48e10062ae41e86cb299f"),
            key: {
              format: "raw" as KeyFormat,
              data: Convert.FromUtf8String("1234567890abcdef"),
              algorithm: { name: "AES-ECB" },
              extractable: true,
              keyUsages: ["encrypt", "decrypt"] as KeyUsage[],
            },
          },
        ],
        import: [
          {
            name: "raw",
            format: "raw" as KeyFormat,
            data: Convert.FromUtf8String("1234567890abcdef"),
            algorithm: "AES-ECB",
            extractable: true,
            keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"] as KeyUsage[],
          },
          {
github PeculiarVentures / webcrypto-liner / test / aes.ts View on Github external
},
    {
      name: "AES-192-GCM",
      actions: {
        generateKey: [
          {
            algorithm: { name: "AES-GCM", length: 192 } as AesKeyGenParams,
            extractable: true,
            keyUsages: ["encrypt", "decrypt"],
          },
        ],
        encrypt: [
          {
            algorithm: {
              name: "AES-GCM",
              iv: Convert.FromUtf8String("1234567890ab"),
            } as AesGcmParams,
            data: Convert.FromUtf8String("test message"),
            encData: Convert.FromHex("d8eab579ed2418f41ca9c4567226f54cb391d3ca2cb6819dace35691"),
            key: {
              format: "raw",
              data: Convert.FromUtf8String("1234567890abcdef12345678"),
              algorithm: { name: "AES-GCM" },
              extractable: true,
              keyUsages: ["encrypt", "decrypt"],
            },
          },
        ],
        import: [
          {
            name: "raw",
            format: "raw",
github PeculiarVentures / webcrypto / test / aes.ts View on Github external
data: Convert.FromUtf8String("test message"),
            encData: Convert.FromHex("84ccef71a364b112eb2b3b8b99587a95"),
            key: {
              format: "raw",
              data: Convert.FromUtf8String("1234567890abcdef1234567809abcdef"),
              algorithm: { name: "AES-ECB" },
              extractable: true,
              keyUsages: ["encrypt", "decrypt"],
            },
          },
        ],
        import: [
          {
            name: "raw",
            format: "raw",
            data: Convert.FromUtf8String("1234567890abcdef1234567890abcdef"),
            algorithm: "AES-ECB",
            extractable: true,
            keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
          },
          {
            name: "jwk",
            format: "jwk",
            data: {
              kty: "oct",
              alg: "A256ECB",
              k: "MTIzNDU2Nzg5MGFiY2RlZjEyMzQ1Njc4OTBhYmNkZWY",
              ext: true,
              key_ops: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
            },
            algorithm: "AES-ECB",
            extractable: true,
github PeculiarVentures / webcrypto-liner / test / des.ts View on Github external
},
    {
      name: "DES-EDE3-CBC",
      actions: {
        generateKey: [
          {
            algorithm: { name: "DES-EDE3-CBC", length: 192 } as core.DesKeyGenParams,
            extractable: false,
            keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"] as KeyUsage[],
          },
        ],
        encrypt: [
          {
            algorithm: {
              name: "DES-EDE3-CBC",
              iv: Convert.FromUtf8String("12345678"),
            } as core.DesParams,
            data: Convert.FromUtf8String("test message"),
            encData: Convert.FromHex("b9ef20e7db926490e4ff8680d99d2141"),
            key: {
              format: "raw" as KeyFormat,
              algorithm: { name: "DES-EDE3-CBC" },
              extractable: true,
              keyUsages: ["encrypt", "decrypt"] as KeyUsage[],
              data: Convert.FromUtf8String("1234567890abcdef12345678"),
            },
          },
        ],
        import: [
          {
            name: "raw",
            format: "raw" as KeyFormat,