How to use the kdbxweb.ByteUtils function in kdbxweb

To help you get started, we’ve selected a few kdbxweb 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 keeweb / keeweb / app / scripts / models / file-model.js View on Github external
addCustomIcon(iconData) {
        const uuid = kdbxweb.KdbxUuid.random();
        this.db.meta.customIcons[uuid] = kdbxweb.ByteUtils.arrayToBuffer(
            kdbxweb.ByteUtils.base64ToBytes(iconData)
        );
        return uuid.toString();
    }
github keeweb / keeweb / app / scripts / util / icon-url.js View on Github external
toDataUrl(iconData) {
        return iconData
            ? 'data:image/png;base64,' + kdbxweb.ByteUtils.bytesToBase64(iconData)
            : null;
    }
};
github keeweb / keeweb / app / scripts / comp / format / kdbx-to-html.js View on Github external
.map(([name, data]) => {
            if (data && data.ref) {
                data = data.value;
            }
            if (data) {
                const base64 = kdbxweb.ByteUtils.bytesToBase64(data);
                data = 'data:application/octet-stream;base64,' + base64;
            }
            return { name, data };
        })
        .filter(att => att.name && att.data);
github keeweb / keeweb / app / scripts / util / data / signature-verifier.js View on Github external
return new Promise((resolve, reject) => {
            const algo = { name: 'RSASSA-PKCS1-v1_5', hash: { name: 'SHA-256' } };
            try {
                if (!pk) {
                    pk = this.getPublicKey();
                }
                if (typeof signature === 'string') {
                    signature = kdbxweb.ByteUtils.base64ToBytes(signature);
                }
                const subtle = window.crypto.subtle;
                const keyFormat = 'spki';
                pk = kdbxweb.ByteUtils.base64ToBytes(pk);
                subtle
                    .importKey(keyFormat, pk, algo, false, ['verify'])
                    .then(cryptoKey => {
                        try {
                            subtle
                                .verify(
                                    algo,
                                    cryptoKey,
                                    kdbxweb.ByteUtils.arrayToBuffer(signature),
                                    kdbxweb.ByteUtils.arrayToBuffer(data)
                                )
                                .then(isValid => {
github keeweb / keeweb / app / scripts / comp / secure-input.js View on Github external
get() {
        const pseudoValue = this.pseudoValue;
        const salt = this.salt;
        const len = pseudoValue.length;
        let byteLength = 0;
        const valueBytes = new Uint8Array(len * 4);
        const saltBytes = kdbxweb.Random.getBytes(len * 4);
        let ch;
        let bytes;
        for (let i = 0; i < len; i++) {
            ch = String.fromCharCode(pseudoValue.charCodeAt(i) ^ salt[i]);
            bytes = kdbxweb.ByteUtils.stringToBytes(ch);
            for (let j = 0; j < bytes.length; j++) {
                valueBytes[byteLength] = bytes[j] ^ saltBytes[byteLength];
                byteLength++;
            }
        }
        return new kdbxweb.ProtectedValue(
            valueBytes.buffer.slice(0, byteLength),
            saltBytes.buffer.slice(0, byteLength)
        );
    }
});
github keeweb / keeweb / app / scripts / plugins / plugin-gallery.js View on Github external
verifySignature(gallery) {
        const dataToVerify = JSON.stringify(gallery, null, 2).replace(gallery.signature, '');
        return SignatureVerifier.verify(
            kdbxweb.ByteUtils.stringToBytes(dataToVerify),
            gallery.signature
        )
            .then(isValid => {
                if (isValid) {
                    return gallery;
                }
                this.logger.error('JSON signature invalid');
            })
            .catch(e => {
                this.logger.error('Error verifying plugins signature', e);
            });
    },
github keeweb / keeweb / app / scripts / models / file-model.js View on Github external
.then(db => {
                    this.db = db;
                    this.readModel();
                    this.setOpenFile({ passwordLength: password ? password.textLength : 0 });
                    if (keyFileData) {
                        kdbxweb.ByteUtils.zeroBuffer(keyFileData);
                    }
                    logger.info(
                        'Opened file ' +
                            this.name +
                            ': ' +
                            logger.ts(ts) +
                            ', ' +
                            this.kdfArgsToString(db.header) +
                            ', ' +
                            Math.round(fileData.byteLength / 1024) +
                            ' kB'
                    );
                    callback();
                })
                .catch(err => {
github keeweb / keeweb / app / scripts / views / open-view.js View on Github external
this.params.id = null;
                            this.params.fileData = e.target.result;
                            this.params.name = file.name.replace(/(.+)\.\w+$/i, '$1');
                            this.params.path = file.path || null;
                            this.params.storage = file.path ? 'file' : null;
                            this.params.rev = null;
                            if (!this.params.keyFileData) {
                                this.params.keyFileName = null;
                            }
                            this.displayOpenFile();
                            this.displayOpenKeyFile();
                            success = true;
                            break;
                        case 'xml':
                            this.params.id = null;
                            this.params.fileXml = kdbxweb.ByteUtils.bytesToString(e.target.result);
                            this.params.name = file.name.replace(/\.\w+$/i, '');
                            this.params.path = null;
                            this.params.storage = null;
                            this.params.rev = null;
                            this.importDbWithXml();
                            success = true;
                            break;
                        case 'kdb':
                            Alerts.error({
                                header: Locale.openWrongFile,
                                body: Locale.openKdbFileBody
                            });
                            break;
                        default:
                            Alerts.error({
                                header: Locale.openWrongFile,
github keeweb / keeweb / app / scripts / plugins / plugin.js View on Github external
return Promise.resolve().then(() => {
            const text = kdbxweb.ByteUtils.bytesToString(data);
            const id = 'plugin-css-' + name;
            this.createElementInHead('style', id, 'text/css', text);
            if (theme) {
                const locKey = this.getThemeLocaleKey(theme.name);
                SettingsManager.allThemes[theme.name] = locKey;
                BaseLocale[locKey] = theme.title;
                for (const styleSheet of Array.from(document.styleSheets)) {
                    if (styleSheet.ownerNode.id === id) {
                        this.processThemeStyleSheet(styleSheet, theme);
                        break;
                    }
                }
            }
            this.logger.debug('Plugin style installed');
        });
    }
github keeweb / keeweb / app / scripts / models / file-model.js View on Github external
readKdfParams() {
        const kdfParameters = this.db.header.kdfParameters;
        if (!kdfParameters) {
            return undefined;
        }
        let uuid = kdfParameters.get('$UUID');
        if (!uuid) {
            return undefined;
        }
        uuid = kdbxweb.ByteUtils.bytesToBase64(uuid);
        switch (uuid) {
            case kdbxweb.Consts.KdfId.Argon2:
                return {
                    parallelism: kdfParameters.get('P').valueOf(),
                    iterations: kdfParameters.get('I').valueOf(),
                    memory: kdfParameters.get('M').valueOf()
                };
            case kdbxweb.Consts.KdfId.Aes:
                return {
                    rounds: kdfParameters.get('R').valueOf()
                };
            default:
                return undefined;
        }
    }