How to use the webcrypto-core.WebCryptoError function in webcrypto-core

To help you get started, we’ve selected a few webcrypto-core 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 / node-webcrypto-ossl / lib / crypto / rsa.ts View on Github external
native.Key.importJwk(data, keyType, (err, key) => {
                        try {
                            if (err) {
                                reject(new WebCryptoError(`ImportKey: Cannot import key from JWK\n${err}`));
                            } else {
                                resolve(key);
                            }
                        } catch (e) {
                            reject(e);
                        }
                    });
                    break;
                case "pkcs8":
                case "spki":
                    if (!Buffer.isBuffer(keyData)) {
                        throw new WebCryptoError("ImportKey: keyData is not a Buffer");
                    }
                    let importFunction = native.Key.importSpki;
                    if (formatLC === "pkcs8") {
                        keyType = native.KeyType.PRIVATE;
                        importFunction = native.Key.importPkcs8;
                    }
                    importFunction(keyData as Buffer, (err, key) => {
                        try {
                            if (err) {
                                reject(new WebCryptoError(`ImportKey: Can not import key for ${format}\n${err.message}`));
                            } else {
                                resolve(key);
                            }
                        } catch (e) {
                            reject(e);
                        }
github PeculiarVentures / node-webcrypto-ossl / lib / crypto / rsa.ts View on Github external
native.Key.generateRsa(size, nExp, (err, key) => {
                try {
                    if (err) {
                        reject(new WebCryptoError(`Rsa: Can not generate new key\n${err.message}`));
                    } else {
                        const prvUsages = ["sign", "decrypt", "unwrapKey"]
                            .filter((usage) => keyUsages.some((keyUsage) => keyUsage === usage)) as KeyUsage[];
                        const pubUsages = ["verify", "encrypt", "wrapKey"]
                            .filter((usage) => keyUsages.some((keyUsage) => keyUsage === usage)) as KeyUsage[];
                        resolve({
                            privateKey: new CryptoKey(key, algorithm, "private", extractable, prvUsages),
                            publicKey: new CryptoKey(key, algorithm, "public", true, pubUsages),
                        });
                    }
                } catch (e) {
                    reject(e);
                }
            });
        });
github PeculiarVentures / node-webcrypto-ossl / lib / crypto / rsa.ts View on Github external
nativeKey.RsaOaepEncDec(alg, data, label, type, (err, res) => {
                if (err) {
                    reject(new WebCryptoError("NativeError: " + err));
                } else {
                    resolve(res.buffer as ArrayBuffer);
                }
            });
        });