How to use the webcrypto-core.Base64Url.decode 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 / webcrypto-liner / src / ec / crypto.ts View on Github external
extractable,
                    usages: keyUsages,
                });
                if (format.toLowerCase() === "jwk") {
                    const namedCurve = this.getNamedCurve((algorithm as EcKeyImportParams).namedCurve);
                    console.log(namedCurve);
                    const ecKey = new elliptic.ec(namedCurve);
                    if ((keyData as JsonWebKey).d) {
                        // Private key
                        key.key = ecKey.keyFromPrivate(Base64Url.decode((keyData as JsonWebKey).d!));
                        key.type = "private";
                    } else {
                        // Public key
                        const bufferPubKey = concat(
                            new Uint8Array([4]),
                            Base64Url.decode((keyData as JsonWebKey).x!),
                            Base64Url.decode((keyData as JsonWebKey).y!),
                        );
                        const hexPubKey = buffer2hex(bufferPubKey);

                        key.key = ecKey.keyFromPublic(hexPubKey, "hex");
                        key.type = "public";
                    }
                } else {
                    throw new LinerError(`Format '${format}' is not implemented`);
                }
                return key;
            });
    }
github PeculiarVentures / webcrypto-liner / src / ec / crypto.ts View on Github external
usages: keyUsages,
                });
                if (format.toLowerCase() === "jwk") {
                    const namedCurve = this.getNamedCurve((algorithm as EcKeyImportParams).namedCurve);
                    console.log(namedCurve);
                    const ecKey = new elliptic.ec(namedCurve);
                    if ((keyData as JsonWebKey).d) {
                        // Private key
                        key.key = ecKey.keyFromPrivate(Base64Url.decode((keyData as JsonWebKey).d!));
                        key.type = "private";
                    } else {
                        // Public key
                        const bufferPubKey = concat(
                            new Uint8Array([4]),
                            Base64Url.decode((keyData as JsonWebKey).x!),
                            Base64Url.decode((keyData as JsonWebKey).y!),
                        );
                        const hexPubKey = buffer2hex(bufferPubKey);

                        key.key = ecKey.keyFromPublic(hexPubKey, "hex");
                        key.type = "public";
                    }
                } else {
                    throw new LinerError(`Format '${format}' is not implemented`);
                }
                return key;
            });
    }
github PeculiarVentures / webcrypto-liner / src / ec / crypto.ts View on Github external
.then(() => {
                const key: EcCryptoKey = new CryptoKey({
                    algorithm,
                    extractable,
                    usages: keyUsages,
                });
                if (format.toLowerCase() === "jwk") {
                    const namedCurve = this.getNamedCurve((algorithm as EcKeyImportParams).namedCurve);
                    console.log(namedCurve);
                    const ecKey = new elliptic.ec(namedCurve);
                    if ((keyData as JsonWebKey).d) {
                        // Private key
                        key.key = ecKey.keyFromPrivate(Base64Url.decode((keyData as JsonWebKey).d!));
                        key.type = "private";
                    } else {
                        // Public key
                        const bufferPubKey = concat(
                            new Uint8Array([4]),
                            Base64Url.decode((keyData as JsonWebKey).x!),
                            Base64Url.decode((keyData as JsonWebKey).y!),
                        );
                        const hexPubKey = buffer2hex(bufferPubKey);

                        key.key = ecKey.keyFromPublic(hexPubKey, "hex");
                        key.type = "public";
                    }
                } else {
                    throw new LinerError(`Format '${format}' is not implemented`);
                }
github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
.then(() => {
                let jwk: JsonWebKey;
                const key = new CryptoKey({
                    algorithm,
                    extractable,
                    usages,
                });
                key.key = [];
                if (format.toLowerCase() === "jwk") {
                    jwk = keyData as JsonWebKey;
                    key.key[0] = Base64Url.decode(jwk.n!);
                    key.key[1] = Base64Url.decode(jwk.e!)[0] === 3 ? new Uint8Array([0, 0, 0, 3]) : new Uint8Array([0, 1, 0, 1]);
                    if (jwk.d) {
                        key.type = "private";
                        key.key[2] = Base64Url.decode(jwk.d!);
                        key.key[3] = Base64Url.decode(jwk.p!);
                        key.key[4] = Base64Url.decode(jwk.q!);
                        key.key[5] = Base64Url.decode(jwk.dp!);
                        key.key[6] = Base64Url.decode(jwk.dq!);
                        key.key[7] = Base64Url.decode(jwk.qi!);
                    } else {
                        key.type = "public";
                    }
                    return key;
                } else {
                    throw new LinerError(LinerError.NOT_SUPPORTED);
                }
            });
github PeculiarVentures / node-webcrypto-ossl / lib / crypto / rsa.ts View on Github external
function b64_decode(b64url: string): Buffer {
    return Buffer.from(Base64Url.decode(b64url));
}
github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
.then(() => {
                let jwk: JsonWebKey;
                const key = new CryptoKey({
                    algorithm,
                    extractable,
                    usages,
                });
                key.key = [];
                if (format.toLowerCase() === "jwk") {
                    jwk = keyData as JsonWebKey;
                    key.key[0] = Base64Url.decode(jwk.n!);
                    key.key[1] = Base64Url.decode(jwk.e!)[0] === 3 ? new Uint8Array([0, 0, 0, 3]) : new Uint8Array([0, 1, 0, 1]);
                    if (jwk.d) {
                        key.type = "private";
                        key.key[2] = Base64Url.decode(jwk.d!);
                        key.key[3] = Base64Url.decode(jwk.p!);
                        key.key[4] = Base64Url.decode(jwk.q!);
                        key.key[5] = Base64Url.decode(jwk.dp!);
                        key.key[6] = Base64Url.decode(jwk.dq!);
                        key.key[7] = Base64Url.decode(jwk.qi!);
                    } else {
                        key.type = "public";
                    }
                    return key;
                } else {
                    throw new LinerError(LinerError.NOT_SUPPORTED);
                }
            });
    }
github PeculiarVentures / webcrypto-liner / src / aes / crypto.ts View on Github external
public static async importKey(format: string, keyData: JsonWebKey | Uint8Array, algorithm: AlgorithmIdentifier, extractable: boolean, usages: KeyUsage[]): Promise {
        let raw: Uint8Array;
        if (format.toLowerCase() === "jwk") {
            const jwk = keyData as JsonWebKey;
            raw = Base64Url.decode(jwk.k!);
        } else {
            raw = new Uint8Array(keyData as Uint8Array);
        }

        const key = new CryptoKey({
            type: "secret",
            algorithm,
            extractable,
            usages,
        });
        key.key = raw;
        return key;
    }