How to use the webcrypto-core.PrepareData 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 / pbkdf2.ts View on Github external
return new Promise((resolve, reject) => {
            const alg = algorithm as Pbkdf2Params;
            const nativeKey = baseKey.native as native.Pbkdf2Key;
            const hash = Core.PrepareAlgorithm(alg.hash);
            const salt = Buffer.from(Core.PrepareData(alg.salt!, "salt"));
            // derive bits
            nativeKey.deriveBits(this.wc2ssl(hash), salt, alg.iterations, length, (err, raw) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(raw.buffer as ArrayBuffer);
                }
            });
        });
    }
github PeculiarVentures / webcrypto-liner / src / aes / crypto.ts View on Github external
.then(() => {
                let res: Uint8Array;

                switch (algorithm.name.toUpperCase()) {
                    case AlgorithmNames.AesECB:
                        const algECB = algorithm as AesEcbParams;
                        res = asmCrypto.AES_ECB.decrypt(data, key.key, !!algECB.padding) as Uint8Array;
                        break;
                    case AlgorithmNames.AesCBC:
                        const algCBC = algorithm as AesCbcParams;
                        res = asmCrypto.AES_CBC.decrypt(data, key.key, undefined, PrepareData(algCBC.iv as Uint8Array, "iv")) as Uint8Array;
                        break;
                    case AlgorithmNames.AesGCM:
                        const algGCM = algorithm as AesGcmParams;
                        algGCM.tagLength = algGCM.tagLength || 128;
                        let additionalData;
                        if (algGCM.additionalData) {
                            additionalData = PrepareData(algGCM.additionalData, "additionalData");
                        }
                        res = asmCrypto.AES_GCM.decrypt(data, key.key, algGCM.iv as Uint8Array, additionalData, algGCM.tagLength / 8) as Uint8Array;
                        break;
                    default:
                        throw new LinerError(AlgorithmError.UNSUPPORTED_ALGORITHM, algorithm.name);
                }
                return res.buffer;
            });
    }
github PeculiarVentures / webcrypto-liner / src / aes / crypto.ts View on Github external
switch (algorithm.name.toUpperCase()) {
                    case AlgorithmNames.AesECB:
                        const algECB = algorithm as AesEcbParams;
                        res = asmCrypto.AES_ECB.decrypt(data, key.key, !!algECB.padding) as Uint8Array;
                        break;
                    case AlgorithmNames.AesCBC:
                        const algCBC = algorithm as AesCbcParams;
                        res = asmCrypto.AES_CBC.decrypt(data, key.key, undefined, PrepareData(algCBC.iv as Uint8Array, "iv")) as Uint8Array;
                        break;
                    case AlgorithmNames.AesGCM:
                        const algGCM = algorithm as AesGcmParams;
                        algGCM.tagLength = algGCM.tagLength || 128;
                        let additionalData;
                        if (algGCM.additionalData) {
                            additionalData = PrepareData(algGCM.additionalData, "additionalData");
                        }
                        res = asmCrypto.AES_GCM.decrypt(data, key.key, algGCM.iv as Uint8Array, additionalData, algGCM.tagLength / 8) as Uint8Array;
                        break;
                    default:
                        throw new LinerError(AlgorithmError.UNSUPPORTED_ALGORITHM, algorithm.name);
                }
                return res.buffer;
            });
    }
github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
switch ((keyAlg.hash as Algorithm).name.toUpperCase()) {
                            case AlgorithmNames.Sha1:
                                decrypt = asmCrypto.RSA_OAEP_SHA1.decrypt;
                                break;
                            case AlgorithmNames.Sha256:
                                decrypt = asmCrypto.RSA_OAEP_SHA256.decrypt;
                                break;
                            case AlgorithmNames.Sha512:
                                decrypt = asmCrypto.RSA_OAEP_SHA512.decrypt;
                                break;
                            default:
                                throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, `${keyAlg.name} ${(keyAlg.hash as Algorithm).name}`);
                        }
                        let label;
                        if (rsaAlg.label) {
                            label = PrepareData(rsaAlg.label, "label");
                        }
                        return decrypt(data, key.key, label);
                    default:
                        throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, algorithm.name);
                }
            });
    }
github PeculiarVentures / webcrypto-liner / src / aes / crypto.ts View on Github external
.then(() => {
                let res: Uint8Array;
                switch (algorithm.name.toUpperCase()) {
                    case AlgorithmNames.AesECB:
                        const algECB = algorithm as AesEcbParams;
                        res = asmCrypto.AES_ECB.encrypt(data, key.key, !!algECB.padding) as Uint8Array;
                        break;
                    case AlgorithmNames.AesCBC:
                        const algCBC = algorithm as AesCbcParams;
                        res = asmCrypto.AES_CBC.encrypt(data, key.key, undefined, PrepareData(algCBC.iv as Uint8Array, "iv")) as Uint8Array;
                        break;
                    case AlgorithmNames.AesGCM:
                        const algGCM = algorithm as AesGcmParams;
                        algGCM.tagLength = algGCM.tagLength || 128;
                        let additionalData;
                        if (algGCM.additionalData) {
                            additionalData = PrepareData(algGCM.additionalData, "additionalData");
                        }
                        res = asmCrypto.AES_GCM.encrypt(data, key.key, algGCM.iv as Uint8Array, additionalData, algGCM.tagLength / 8) as Uint8Array;
                        break;
                    default:
                        throw new LinerError(AlgorithmError.UNSUPPORTED_ALGORITHM, algorithm.name);
                }
                return res.buffer;
            });
    }
github PeculiarVentures / webcrypto-liner / src / aes / crypto.ts View on Github external
let res: Uint8Array;
                switch (algorithm.name.toUpperCase()) {
                    case AlgorithmNames.AesECB:
                        const algECB = algorithm as AesEcbParams;
                        res = asmCrypto.AES_ECB.encrypt(data, key.key, !!algECB.padding) as Uint8Array;
                        break;
                    case AlgorithmNames.AesCBC:
                        const algCBC = algorithm as AesCbcParams;
                        res = asmCrypto.AES_CBC.encrypt(data, key.key, undefined, PrepareData(algCBC.iv as Uint8Array, "iv")) as Uint8Array;
                        break;
                    case AlgorithmNames.AesGCM:
                        const algGCM = algorithm as AesGcmParams;
                        algGCM.tagLength = algGCM.tagLength || 128;
                        let additionalData;
                        if (algGCM.additionalData) {
                            additionalData = PrepareData(algGCM.additionalData, "additionalData");
                        }
                        res = asmCrypto.AES_GCM.encrypt(data, key.key, algGCM.iv as Uint8Array, additionalData, algGCM.tagLength / 8) as Uint8Array;
                        break;
                    default:
                        throw new LinerError(AlgorithmError.UNSUPPORTED_ALGORITHM, algorithm.name);
                }
                return res.buffer;
            });
    }