How to use the webcrypto-core.Base64Url.encode 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
nativeKey.exportJwk(type, (err, data) => {
                        try {
                            const jwk: JsonWebKey = { kty: "RSA" };
                            jwk.key_ops = key.usages;

                            // convert base64 -> base64url for all props
                            jwk.e = Base64Url.encode(data.e);
                            jwk.n = Base64Url.encode(data.n);
                            if (key.type === "private") {
                                jwk.d = Base64Url.encode(data.d);
                                jwk.p = Base64Url.encode(data.p);
                                jwk.q = Base64Url.encode(data.q);
                                jwk.dp = Base64Url.encode(data.dp);
                                jwk.dq = Base64Url.encode(data.dq);
                                jwk.qi = Base64Url.encode(data.qi);
                            }
                            resolve(jwk);
                        } catch (e) {
                            reject(e);
                        }
                    });
                    break;
github PeculiarVentures / node-webcrypto-ossl / lib / crypto / rsa.ts View on Github external
nativeKey.exportJwk(type, (err, data) => {
                        try {
                            const jwk: JsonWebKey = { kty: "RSA" };
                            jwk.key_ops = key.usages;

                            // convert base64 -> base64url for all props
                            jwk.e = Base64Url.encode(data.e);
                            jwk.n = Base64Url.encode(data.n);
                            if (key.type === "private") {
                                jwk.d = Base64Url.encode(data.d);
                                jwk.p = Base64Url.encode(data.p);
                                jwk.q = Base64Url.encode(data.q);
                                jwk.dp = Base64Url.encode(data.dp);
                                jwk.dq = Base64Url.encode(data.dq);
                                jwk.qi = Base64Url.encode(data.qi);
                            }
                            resolve(jwk);
                        } catch (e) {
                            reject(e);
                        }
                    });
                    break;
github PeculiarVentures / node-webcrypto-ossl / lib / crypto / rsa.ts View on Github external
nativeKey.exportJwk(type, (err, data) => {
                        try {
                            const jwk: JsonWebKey = { kty: "RSA" };
                            jwk.key_ops = key.usages;

                            // convert base64 -> base64url for all props
                            jwk.e = Base64Url.encode(data.e);
                            jwk.n = Base64Url.encode(data.n);
                            if (key.type === "private") {
                                jwk.d = Base64Url.encode(data.d);
                                jwk.p = Base64Url.encode(data.p);
                                jwk.q = Base64Url.encode(data.q);
                                jwk.dp = Base64Url.encode(data.dp);
                                jwk.dq = Base64Url.encode(data.dq);
                                jwk.qi = Base64Url.encode(data.qi);
                            }
                            resolve(jwk);
                        } catch (e) {
                            reject(e);
                        }
                    });
                    break;
github PeculiarVentures / webcrypto-liner / src / ec / crypto.ts View on Github external
// public
                        const jwk: JsonWebKey = {
                            crv: (key.algorithm as EcKeyGenParams).namedCurve,
                            ext: key.extractable,
                            x: Base64Url.encode(hex2buffer(hexX, true)),
                            y: Base64Url.encode(hex2buffer(hexY, true)),
                            key_ops: key.usages,
                            kty: "EC",
                        };
                        return jwk;
                    } else {
                        // private
                        const jwk: JsonWebKey = {
                            crv: (key.algorithm as EcKeyGenParams).namedCurve,
                            ext: key.extractable,
                            d: Base64Url.encode(hex2buffer(ecKey.getPrivate("hex"), true)),
                            x: Base64Url.encode(hex2buffer(hexX, true)),
                            y: Base64Url.encode(hex2buffer(hexY, true)),
                            key_ops: key.usages,
                            kty: "EC",
                        };
                        return jwk;
                    }
                } else {
                    throw new LinerError(`Format '${format}' is not implemented`);
                }
            });
    }
github PeculiarVentures / node-webcrypto-ossl / lib / crypto / rsa.ts View on Github external
nativeKey.exportJwk(type, (err, data) => {
                        try {
                            const jwk: JsonWebKey = { kty: "RSA" };
                            jwk.key_ops = key.usages;

                            // convert base64 -> base64url for all props
                            jwk.e = Base64Url.encode(data.e);
                            jwk.n = Base64Url.encode(data.n);
                            if (key.type === "private") {
                                jwk.d = Base64Url.encode(data.d);
                                jwk.p = Base64Url.encode(data.p);
                                jwk.q = Base64Url.encode(data.q);
                                jwk.dp = Base64Url.encode(data.dp);
                                jwk.dq = Base64Url.encode(data.dq);
                                jwk.qi = Base64Url.encode(data.qi);
                            }
                            resolve(jwk);
                        } catch (e) {
                            reject(e);
                        }
                    });
                    break;
github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
.then(() => {
                if (format.toLowerCase() === "jwk") {
                    const jwk: JsonWebKey = {
                        kty: "RSA",
                        ext: true,
                        key_ops: key.usages,
                    };
                    jwk.alg = this.alg2jwk(key.algorithm as Algorithm);
                    jwk.n = Base64Url.encode(removeLeadingZero(key.key[0]));
                    jwk.e = Base64Url.encode(removeLeadingZero(key.key[1]));
                    if (key.type === "private") {
                        jwk.d = Base64Url.encode(removeLeadingZero(key.key[2]));
                        jwk.p = Base64Url.encode(removeLeadingZero(key.key[3]));
                        jwk.q = Base64Url.encode(removeLeadingZero(key.key[4]));
                        jwk.dp = Base64Url.encode(removeLeadingZero(key.key[5]));
                        jwk.dq = Base64Url.encode(removeLeadingZero(key.key[6]));
                        jwk.qi = Base64Url.encode(removeLeadingZero(key.key[7]));
                    }
                    return jwk;
                } else {
                    throw new LinerError(LinerError.NOT_SUPPORTED);
                }
            });
    }
github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
.then(() => {
                if (format.toLowerCase() === "jwk") {
                    const jwk: JsonWebKey = {
                        kty: "RSA",
                        ext: true,
                        key_ops: key.usages,
                    };
                    jwk.alg = this.alg2jwk(key.algorithm as Algorithm);
                    jwk.n = Base64Url.encode(removeLeadingZero(key.key[0]));
                    jwk.e = Base64Url.encode(removeLeadingZero(key.key[1]));
                    if (key.type === "private") {
                        jwk.d = Base64Url.encode(removeLeadingZero(key.key[2]));
                        jwk.p = Base64Url.encode(removeLeadingZero(key.key[3]));
                        jwk.q = Base64Url.encode(removeLeadingZero(key.key[4]));
                        jwk.dp = Base64Url.encode(removeLeadingZero(key.key[5]));
                        jwk.dq = Base64Url.encode(removeLeadingZero(key.key[6]));
                        jwk.qi = Base64Url.encode(removeLeadingZero(key.key[7]));
                    }
                    return jwk;
                } else {
                    throw new LinerError(LinerError.NOT_SUPPORTED);
                }
            });
    }
github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
if (format.toLowerCase() === "jwk") {
                    const jwk: JsonWebKey = {
                        kty: "RSA",
                        ext: true,
                        key_ops: key.usages,
                    };
                    jwk.alg = this.alg2jwk(key.algorithm as Algorithm);
                    jwk.n = Base64Url.encode(removeLeadingZero(key.key[0]));
                    jwk.e = Base64Url.encode(removeLeadingZero(key.key[1]));
                    if (key.type === "private") {
                        jwk.d = Base64Url.encode(removeLeadingZero(key.key[2]));
                        jwk.p = Base64Url.encode(removeLeadingZero(key.key[3]));
                        jwk.q = Base64Url.encode(removeLeadingZero(key.key[4]));
                        jwk.dp = Base64Url.encode(removeLeadingZero(key.key[5]));
                        jwk.dq = Base64Url.encode(removeLeadingZero(key.key[6]));
                        jwk.qi = Base64Url.encode(removeLeadingZero(key.key[7]));
                    }
                    return jwk;
                } else {
                    throw new LinerError(LinerError.NOT_SUPPORTED);
                }
            });
    }
github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
.then(() => {
                if (format.toLowerCase() === "jwk") {
                    const jwk: JsonWebKey = {
                        kty: "RSA",
                        ext: true,
                        key_ops: key.usages,
                    };
                    jwk.alg = this.alg2jwk(key.algorithm as Algorithm);
                    jwk.n = Base64Url.encode(removeLeadingZero(key.key[0]));
                    jwk.e = Base64Url.encode(removeLeadingZero(key.key[1]));
                    if (key.type === "private") {
                        jwk.d = Base64Url.encode(removeLeadingZero(key.key[2]));
                        jwk.p = Base64Url.encode(removeLeadingZero(key.key[3]));
                        jwk.q = Base64Url.encode(removeLeadingZero(key.key[4]));
                        jwk.dp = Base64Url.encode(removeLeadingZero(key.key[5]));
                        jwk.dq = Base64Url.encode(removeLeadingZero(key.key[6]));
                        jwk.qi = Base64Url.encode(removeLeadingZero(key.key[7]));
                    }
                    return jwk;
                } else {
                    throw new LinerError(LinerError.NOT_SUPPORTED);
                }
            });
    }
github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
.then(() => {
                if (format.toLowerCase() === "jwk") {
                    const jwk: JsonWebKey = {
                        kty: "RSA",
                        ext: true,
                        key_ops: key.usages,
                    };
                    jwk.alg = this.alg2jwk(key.algorithm as Algorithm);
                    jwk.n = Base64Url.encode(removeLeadingZero(key.key[0]));
                    jwk.e = Base64Url.encode(removeLeadingZero(key.key[1]));
                    if (key.type === "private") {
                        jwk.d = Base64Url.encode(removeLeadingZero(key.key[2]));
                        jwk.p = Base64Url.encode(removeLeadingZero(key.key[3]));
                        jwk.q = Base64Url.encode(removeLeadingZero(key.key[4]));
                        jwk.dp = Base64Url.encode(removeLeadingZero(key.key[5]));
                        jwk.dq = Base64Url.encode(removeLeadingZero(key.key[6]));
                        jwk.qi = Base64Url.encode(removeLeadingZero(key.key[7]));
                    }
                    return jwk;
                } else {
                    throw new LinerError(LinerError.NOT_SUPPORTED);
                }
            });
    }