How to use pvtsutils - 10 common examples

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
it(item.name, async () => {
                            const buf = Convert.FromHex(item.raw);
                            const bundle = await PreKeyBundleProtocol.importProto(buf);
                            const identity = await createIdentity(2);

                            try {
                                await AsymmetricRatchet.create(identity, bundle);
                                assert.isTrue(false, "Must be error");
                            } catch (err) {
                                // console.log(err.message);
                            }
                        });
                    });
github PeculiarVentures / 2key-ratchet / test / encryption.ts View on Github external
it("wrong order", async () => {
        const ciphers = await createCiphers();
        const { Alice, Bob } = ciphers;

        const AliceMsg1 = await Alice.encrypt(MESSAGE) as MessageSignedProtocol; // slow message
        await dialog(Alice, Bob, 5);
        assert.isTrue(isEqual(await Bob.decrypt(AliceMsg1), MESSAGE));
        await dialog(Alice, Bob, 5);
    });
github PeculiarVentures / webcrypto-liner / test / script / rsa.ts View on Github external
data: {
              alg: "RS256",
              e: "AQAB",
              ext: true,
              key_ops: ["verify"],
              kty: "RSA",
              n: "vqpvdxuyZ6rKYnWTj_ZzDBFZAAAlpe5hpoiYHqa2j5kK7v8U5EaPY2bLib9m4B40j-n3FV9xUCGiplWdqMJJKT-4PjGO5E3S4N9kjFhu57noYT7z7302J0sJXeoFbXxlgE-4G55Oxlm52ID2_RJesP5nzcGTriQwoRbrJP5OEt0",
            },
            extractable: true,
            keyUsages: ["verify"] as KeyUsage[],
          },
          { // public key SPKI
            name: "public key SPKI",
            format: "spki" as KeyFormat,
            algorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" } as Algorithm,
            data: Convert.FromBase64("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+qm93G7JnqspidZOP9nMMEVkAACWl7mGmiJgepraPmQru/xTkRo9jZsuJv2bgHjSP6fcVX3FQIaKmVZ2owkkpP7g+MY7kTdLg32SMWG7nuehhPvPvfTYnSwld6gVtfGWAT7gbnk7GWbnYgPb9El6w/mfNwZOuJDChFusk/k4S3QIDAQAB"),
            extractable: true,
            keyUsages: ["verify"] as KeyUsage[],
          },
          { // private key JWK
            name: "private key JWK",
            format: "jwk" as KeyFormat,
            algorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" } as Algorithm,
            data: {
              alg: "RS256",
              d: "YZzAFCqJ26kElAO92CZEIBmBhw6MN7cjJy8nMgoHzNx9TH4rI_M71Zf6_DqRYIwWPNd7N-X1DSErNB0A6jUNXr42l3ChBsBB31vjHqQKx95-M6iXVgjJFTzxirNjUuCm_skFYIcXS5oEaXjy5XI3dT8KAEf1M2UA6__LwGrAD8E",
              dp: "pOolqL7HwnmWLn7GDX8zGkm0Q1IAj-ouBL7ZZbaTm3wETLtwu-dGsQheEdzP_mfL_CTiCAwGuQBcSItimD0DdQ",
              dq: "FTSY59AnkgmB7TsErWNBE3xlVB_pMpE2xWyCBCz96gyDOUOFDz8vlSV-clhjawJeRd1n30nZOPSBtOHozhwZmQ",
              e: "AQAB",
              ext: true,
              key_ops: ["sign"],
              kty: "RSA",
github PeculiarVentures / webcrypto-liner / test / script / rsa.ts View on Github external
key_ops: ["sign"],
              kty: "RSA",
              n: "vqpvdxuyZ6rKYnWTj_ZzDBFZAAAlpe5hpoiYHqa2j5kK7v8U5EaPY2bLib9m4B40j-n3FV9xUCGiplWdqMJJKT-4PjGO5E3S4N9kjFhu57noYT7z7302J0sJXeoFbXxlgE-4G55Oxlm52ID2_RJesP5nzcGTriQwoRbrJP5OEt0",
              p: "6jFtmBJJQFIlQUXXZYIgvH70Y9a03oWKjNuF2veb5Zf09EtLNE86NpnIm463OnoHJPW0m8wHFXZZfcYVTIPR_w",
              q: "0GttDMl1kIzSV2rNzGXpOS8tUqr5Lz0EtVZwIb9GJPMmJ0P3gZ801zEgZZ4-esU7cLUf-BSZEAmfnKA80G2jIw",
              qi: "FByTxX4G2eXkk1xe0IuiEv7I5NS-CnFyp8iB4XLG0rabnfcIZFKpf__X0sNyVOAVo5-jJMuUYjCRTdaXNAWhkg",
            },
            extractable: true,
            keyUsages: ["sign"] as KeyUsage[],
          },
          {
            skip: browser.name === Browser.Edge, // Edge returns PKCS8 with KeyUsages extension
            name: "private key pkcs8",
            format: "pkcs8" as KeyFormat,
            algorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" } as Algorithm,
            data: Convert.FromBase64("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL6qb3cbsmeqymJ1k4/2cwwRWQAAJaXuYaaImB6mto+ZCu7/FORGj2Nmy4m/ZuAeNI/p9xVfcVAhoqZVnajCSSk/uD4xjuRN0uDfZIxYbue56GE+8+99NidLCV3qBW18ZYBPuBueTsZZudiA9v0SXrD+Z83Bk64kMKEW6yT+ThLdAgMBAAECgYACR4hYnLCn059iyPQQKwqaENUHDnlkv/JT6tsitqyFD/fU/qCxz/Qj5JU3Wt3wfPv04n+tNjxlEFng8jIV0+jK+6jlqkd0AcfquIkrEMdY/GET5F41UQ9JOIXWvLwNJ7nMLvD0Eucf9AzxuQ3hw6e+CquDsRusZaiYAYlW+hHA4wJBAOoxbZgSSUBSJUFF12WCILx+9GPWtN6Fiozbhdr3m+WX9PRLSzRPOjaZyJuOtzp6ByT1tJvMBxV2WX3GFUyD0f8CQQDQa20MyXWQjNJXas3MZek5Ly1SqvkvPQS1VnAhv0Yk8yYnQ/eBnzTXMSBlnj56xTtwtR/4FJkQCZ+coDzQbaMjAkEApOolqL7HwnmWLn7GDX8zGkm0Q1IAj+ouBL7ZZbaTm3wETLtwu+dGsQheEdzP/mfL/CTiCAwGuQBcSItimD0DdQJAFTSY59AnkgmB7TsErWNBE3xlVB/pMpE2xWyCBCz96gyDOUOFDz8vlSV+clhjawJeRd1n30nZOPSBtOHozhwZmQJAFByTxX4G2eXkk1xe0IuiEv7I5NS+CnFyp8iB4XLG0rabnfcIZFKpf//X0sNyVOAVo5+jJMuUYjCRTdaXNAWhkg=="),
            extractable: true,
            keyUsages: ["sign"] as KeyUsage[],
          },
          {
            name: "pkcs8 e:03 n:1024",
            skip: browser.name === Browser.Edge,
            format: "pkcs8" as KeyFormat,
            algorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-1" } as Algorithm,
            data: Convert.FromBase64("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMvnUNSnYnGqOvXyTmakC8UHNMu3Mriovo+rwfiddT7yCF4Zg/b5WLcn49ItVMgqTuM80naBC2CcDbtM1nFgDRCmUTLGrRZDBMyny/P88AliOws3Hw7iDjfdV7rR1TNlaONtrBfwl6CARPfubYSgKyAdck97em6Wgx8PSpFHcGhnAgEDAoGAIfvizhvlvZxfKP23u8YB9iveIfPdyXF1F/H1qW+Tin2sD67rU9Q5c9v7TbI4zAcNJd94aRWB5W9Xnzd5EuVXgnnU/wz54Bk6zXMLq/L6oouSLzcRVwz0riaXBa007OTejfS+jVhCAlMM4hqYnCxrRr4BBIEi+WidyHKSs8ynSE8CQQD9BRizPsw8eZXDcJz1TVrNYVk4ZGgWfmgGkdyeSh2A5Smdcmvzcm32dNVH9fqL9P33qoJUw+CoSRKuEB/szIjjAkEAzk4fxZMJbypmMhVPVcLfT2yWtFKcfdO67zu8JE2Ih0xmE8Jb65kkl4LWBuPhCbJ5scGyH+S1eodZsco6jrgtrQJBAKiuEHd/MtL7uSz1vfjePIjrkNBC8A7+8ARhPb7cE6tDcROhnUz28/mjONqj/F1N/qUcVuMtQHAwtx61ap3dsJcCQQCJiWqDt1ufcZl2uN+Ogeo08w8i4b2pN9H00n1tiQWviEQNLD1Hu226VzlZ7UCxIaZ2gSFqmHj8WjvL3CcJ0B5zAkEAlmRgnALghAcJ/WfTMphPKJXhY+H+CgkeE3si2ZgPW1YaDAyhp/xdQabkgbFy70Nq32fuJyxDDS4WhF0aOYz6pw=="),
            extractable: true,
            keyUsages: ["sign"] as KeyUsage[],
          },
          {
            name: "spki e:03 n:1024",
            format: "spki" as KeyFormat,
            algorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-1" } as Algorithm,
github PeculiarVentures / webcrypto / test / rsa.ts View on Github external
ext: true,
              key_ops: ["sign"],
              kty: "RSA",
              n: "vqpvdxuyZ6rKYnWTj_ZzDBFZAAAlpe5hpoiYHqa2j5kK7v8U5EaPY2bLib9m4B40j-n3FV9xUCGiplWdqMJJKT-4PjGO5E3S4N9kjFhu57noYT7z7302J0sJXeoFbXxlgE-4G55Oxlm52ID2_RJesP5nzcGTriQwoRbrJP5OEt0",
              p: "6jFtmBJJQFIlQUXXZYIgvH70Y9a03oWKjNuF2veb5Zf09EtLNE86NpnIm463OnoHJPW0m8wHFXZZfcYVTIPR_w",
              q: "0GttDMl1kIzSV2rNzGXpOS8tUqr5Lz0EtVZwIb9GJPMmJ0P3gZ801zEgZZ4-esU7cLUf-BSZEAmfnKA80G2jIw",
              qi: "FByTxX4G2eXkk1xe0IuiEv7I5NS-CnFyp8iB4XLG0rabnfcIZFKpf__X0sNyVOAVo5-jJMuUYjCRTdaXNAWhkg",
            },
            extractable: true,
            keyUsages: ["sign"] as KeyUsage[],
          },
          {
            name: "private key pkcs8",
            format: "pkcs8" as KeyFormat,
            algorithm: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" } as RsaHashedImportParams,
            data: Convert.FromBase64("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL6qb3cbsmeqymJ1k4/2cwwRWQAAJaXuYaaImB6mto+ZCu7/FORGj2Nmy4m/ZuAeNI/p9xVfcVAhoqZVnajCSSk/uD4xjuRN0uDfZIxYbue56GE+8+99NidLCV3qBW18ZYBPuBueTsZZudiA9v0SXrD+Z83Bk64kMKEW6yT+ThLdAgMBAAECgYACR4hYnLCn059iyPQQKwqaENUHDnlkv/JT6tsitqyFD/fU/qCxz/Qj5JU3Wt3wfPv04n+tNjxlEFng8jIV0+jK+6jlqkd0AcfquIkrEMdY/GET5F41UQ9JOIXWvLwNJ7nMLvD0Eucf9AzxuQ3hw6e+CquDsRusZaiYAYlW+hHA4wJBAOoxbZgSSUBSJUFF12WCILx+9GPWtN6Fiozbhdr3m+WX9PRLSzRPOjaZyJuOtzp6ByT1tJvMBxV2WX3GFUyD0f8CQQDQa20MyXWQjNJXas3MZek5Ly1SqvkvPQS1VnAhv0Yk8yYnQ/eBnzTXMSBlnj56xTtwtR/4FJkQCZ+coDzQbaMjAkEApOolqL7HwnmWLn7GDX8zGkm0Q1IAj+ouBL7ZZbaTm3wETLtwu+dGsQheEdzP/mfL/CTiCAwGuQBcSItimD0DdQJAFTSY59AnkgmB7TsErWNBE3xlVB/pMpE2xWyCBCz96gyDOUOFDz8vlSV+clhjawJeRd1n30nZOPSBtOHozhwZmQJAFByTxX4G2eXkk1xe0IuiEv7I5NS+CnFyp8iB4XLG0rabnfcIZFKpf//X0sNyVOAVo5+jJMuUYjCRTdaXNAWhkg=="),
            extractable: true,
            keyUsages: ["sign"] as KeyUsage[],
          },
        ],
      },
    },
    // RSA-PSS
    {
      name: "RSA-PSS",
      actions: {
        generateKey: ["SHA-1", "SHA-256", "SHA-384", "SHA-512"].map((hash) => {
          return {
            name: hash,
            algorithm: {
              name: "RSA-PSS",
              hash,
github PeculiarVentures / webcrypto-liner / test / sha.ts View on Github external
algorithm: "SHA-1",
            data,
            hash: Convert.FromBase64("6JrVqWMcPv3e1+Psznm00P7c4b8="),
          },
          {
            name: "SHA-256",
            algorithm: "SHA-256",
            data,
            hash: Convert.FromBase64("monGjExeKLjEpVZ2c9Ri//UV20YRb5kAYk0JxHT1k/s="),
          },
          {
            name: "SHA-384",
            skip: typeof module !== "undefined", // skip for nodejs
            algorithm: "SHA-384",
            data,
            hash: Convert.FromBase64("E9WqubQC9JnxffIniWwf0soI91o5z0Kbvk+s/32Fi3z28kAh+Fcne7Hgy1nnW4rR"),
          },
          {
            name: "SHA-512",
            algorithm: "SHA-512",
            data,
            hash: Convert.FromBase64("OtPzaXlFDU9TNmJE7PEBD0+RIdaIgoX/FBBP1a3thdSKoXG/HjOhEmAvkrenCIsph4kBL7h7kFYyEkGhn7dOCw=="),
          },
        ],
      },
    },
  ]);

});
github PeculiarVentures / webcrypto-liner / test / ec.ts View on Github external
skip: browser.name === Browser.Firefox, // Firefox uses 1.3.132.112 instead of 1.2.840.10045.2.1 for algorithm
            name: "SPKI P-384",
            format: "spki" as KeyFormat,
            data: Convert.FromBase64("MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE8Kf5Wv21nksy0LuMlkMZv9sxTVAmzNWt81b6MVlYuzxl9D2/obwoVp86pTe4BM79gWWj8pfLc1XrjaIyMSrV8+05IejRLB3i4c0KTGA6QARGm3/AOm0MbTt6kMQF7drL"),
            algorithm: {
              name: "ECDSA",
              namedCurve: "P-384",
            } as EcKeyImportParams,
            extractable: true,
            keyUsages: ["verify"],
          },
          {
            skip: browser.name === Browser.Firefox, // Firefox uses 1.3.132.112 instead of 1.2.840.10045.2.1 for algorithm
            name: "SPKI P-521",
            format: "spki" as KeyFormat,
            data: Convert.FromBase64("MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQB+/g37ii0T5iLHCAaXcYRRoNpT0LhfeAr88OwQY4cUpQm1S9lkR0EVUtyuYrYsMB8FarhAZYsLtOiyhjl/Y5f+lQAZ6veWILhbDcbrSNhTPSp3wamAm8QT3EjPUkJlYjHefuAUBIYS9pl5FWjK1pI9fkYe3bdAemkjP1ccHVzqZU9sjg="),
            algorithm: {
              name: "ECDSA",
              namedCurve: "P-521",
            } as EcKeyImportParams,
            extractable: true,
            keyUsages: ["verify"],
          },
          //#endregion
          //#region RAW
          {
            name: "RAW P-256",
            format: "raw" as KeyFormat,
            data: Convert.FromBase64("BEehen4AavxgJkx5EPZpBeopzgZuY+1i3cMR9iYdZj+IY7/h98Q/GboC2BKS6lT0hEyt6y1DFFXj8ytuof4zXR4="),
            algorithm: {
              name: "ECDSA",
              namedCurve: "P-256",
github PeculiarVentures / node-webcrypto-p11 / test / ec.ts View on Github external
// x: "AJGuTezC-8F-d_0bBpS502OK0z63vo87Dw99a3NUm6gm5pQC1rwu7LcblGqFWOuFBZhsF8I6OFjYvsR-z3u7hhCA",
              // y: "AFQT8BB9hBf7UwwBUV4im8bFJ7_MD0qOZMVetmdbooMjfec1q3wU5cSoy4LvCnWAaFqu5havUxwnAUuPUWGG_InR",
            },
            algorithm: {
              name: "ECDSA",
              namedCurve: "P-521",
            } as EcKeyImportParams,
            extractable: true,
            keyUsages: ["sign"],
          },
          //#endregion
          //#region PKCS8
          {
            name: "PKCS8 P-256",
            format: "pkcs8" as KeyFormat,
            data: Convert.FromHex("304d020100301306072a8648ce3d020106082a8648ce3d030107043330310201010420895118e4e168dc9ee0d419d2c3f5845b2918fda96b84d9a91012f2ffb70d9ee1a00a06082a8648ce3d030107"),
            algorithm: {
              name: "ECDSA",
              namedCurve: "P-256",
            } as EcKeyImportParams,
            extractable: true,
            keyUsages: ["sign"],
          },
          {
            name: "PKCS8 P-384",
            format: "pkcs8" as KeyFormat,
            data: Convert.FromHex("3057020100301006072a8648ce3d020106052b810400220440303e020101043098d7c6a318f0a02efe1a17552492884c11a079314d4cc9f92e1504905436072d61539fc7fd73371eeda4c80e3902c743a00706052b81040022"),
            algorithm: {
              name: "ECDSA",
              namedCurve: "P-384",
            } as EcKeyImportParams,
            extractable: true,
github PeculiarVentures / webcrypto / test / helper.ts View on Github external
wrapTest(async () => {
              // import keys
              const keys = await getKeys(crypto, action.key);
              const encKey = keys.publicKey;
              const decKey = keys.privateKey;

              const algorithm = Object.assign({}, action.algorithm);
              algorithm.name = algorithm.name.toLowerCase();

              // encrypt
              const enc = await crypto.subtle.encrypt(algorithm, encKey, action.data);

              // decrypt
              let dec = await crypto.subtle.decrypt(algorithm, decKey, enc);
              assert.equal(Convert.ToHex(dec), Convert.ToHex(action.data));

              dec = await crypto.subtle.decrypt(algorithm, decKey, action.encData);
              assert.equal(Convert.ToHex(dec), Convert.ToHex(action.data));
            }, action, index);
          });
github PeculiarVentures / webcrypto-liner / test / utils / helper.ts View on Github external
const keys = await getKeys(crypto, action.key);
              const verifyKey = keys.publicKey;
              const signKey = keys.privateKey;

              const algorithm = Object.assign({}, action.algorithm);
              algorithm.name = algorithm.name.toLowerCase();

              // sign
              const signature = await crypto.subtle.sign(algorithm, signKey, action.data);
              // verify
              let ok = await crypto.subtle.verify(algorithm, verifyKey, signature, action.data);
              assert.equal(true, ok, "Cannot verify signature from Action data");

              ok = await crypto.subtle.verify(algorithm, verifyKey, action.signature, action.data);
              if (!ok) {
                assert.equal(Convert.ToHex(signature), Convert.ToHex(action.signature));
              }
              assert.equal(true, ok);
            }, action, index);
          });