How to use the kdbxweb.ProtectedValue 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 iotaledger / trinity-wallet / src / desktop / native / libs / kdbx.js View on Github external
const importVault = async (buffer, password) => {
    const credentials = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(password));

    const db = await kdbxweb.Kdbx.load(buffer, credentials);
    const entries = db.getDefaultGroup().entries;
    const seeds = [];

    for (let i = 0; i < entries.length; i++) {
        if (entries[i].fields.Seed) {
            seeds.push({
                title: entries[i].fields.Title || `Seed #${i + 1}`,
                seed: entries[i].fields.Seed.getText()
                    .split('')
                    .map((char) => charToByte(char.toUpperCase()))
                    .filter((byte) => byte > -1),
            });
        }
    }
github keeweb / keeweb / app / scripts / views / fields / field-view-text.js View on Github external
endEdit(newVal, extra) {
        if (this.gen) {
            this.hideGenerator();
        }
        if (!this.editing) {
            return;
        }
        delete this.input;
        if (this.mobileControls) {
            this.mobileControls.cancel.remove();
            this.mobileControls.apply.remove();
            delete this.mobileControls;
        }
        this.stopBlurListener();
        if (typeof newVal === 'string' && this.value instanceof kdbxweb.ProtectedValue) {
            newVal = kdbxweb.ProtectedValue.fromString(newVal);
        }
        if (typeof newVal === 'string') {
            newVal = $.trim(newVal);
        }
        super.endEdit(newVal, extra);
    }
github keeweb / keeweb / app / scripts / views / fields / field-view-custom.js View on Github external
endEdit(newVal, extra) {
        this.$el.removeClass('details__field--can-edit-title');
        extra = Object.assign({}, extra);
        if (this.model.titleChanged || this.model.newField) {
            extra.newField = this.model.title;
        }
        if (!this.editing) {
            return;
        }
        delete this.input;
        if (typeof newVal === 'string') {
            if (this.isProtected) {
                newVal = kdbxweb.ProtectedValue.fromString(newVal);
            } else {
                newVal = $.trim(newVal);
            }
        }
        FieldView.prototype.endEdit.call(this, newVal, extra);
        if (this.model.titleChanged) {
            delete this.model.titleChanged;
        }
    }
github keeweb / keeweb / app / scripts / views / fields / field-view-text.js View on Github external
endEdit(newVal, extra) {
        if (this.gen) {
            this.hideGenerator();
        }
        if (!this.editing) {
            return;
        }
        delete this.input;
        if (this.mobileControls) {
            this.mobileControls.cancel.remove();
            this.mobileControls.apply.remove();
            delete this.mobileControls;
        }
        this.stopBlurListener();
        if (typeof newVal === 'string' && this.value instanceof kdbxweb.ProtectedValue) {
            newVal = kdbxweb.ProtectedValue.fromString(newVal);
        }
        if (typeof newVal === 'string') {
            newVal = $.trim(newVal);
        }
        super.endEdit(newVal, extra);
    }
github keeweb / keeweb / app / scripts / models / entry-model.js View on Github external
let settings = this.entry.fields['TOTP Settings'];
                if (settings && settings.isProtected) {
                    settings = settings.getText();
                }
                let period, digits;
                if (settings) {
                    settings = settings.split(';');
                    if (settings.length > 0 && settings[0] > 0) {
                        period = settings[0];
                    }
                    if (settings.length > 1 && settings[1] > 0) {
                        digits = settings[1];
                    }
                }
                otpUrl = Otp.makeUrl(secret, period, digits);
                this.fields.otp = kdbxweb.ProtectedValue.fromString(otpUrl);
            }
        }
        if (otpUrl) {
            if (this.otpGenerator && this.otpGenerator.url === otpUrl) {
                return;
            }
            try {
                this.otpGenerator = Otp.parseUrl(otpUrl);
            } catch (e) {
                this.otpGenerator = null;
            }
        } else {
            this.otpGenerator = null;
        }
    }
github keeweb / keeweb / app / scripts / views / import-csv-view.js View on Github external
file = this.appModel.createNewFile(fileName);
            group = file.groups[0];
        }
        for (const row of this.model.rows) {
            const newEntry = EntryModel.newEntry(group, file);
            for (let ix = 0; ix < row.length; ix++) {
                let value = row[ix];
                if (!value) {
                    continue;
                }
                const mapping = this.fieldMapping[ix];
                if (mapping.type === 'ignore' || !mapping.field) {
                    continue;
                }
                if (mapping.field === 'password') {
                    value = kdbxweb.ProtectedValue.fromString(value);
                }
                newEntry.setField(mapping.field, value);
            }
        }
        file.reload();
        this.emit('done');
    }
}
github keeweb / keeweb / app / scripts / comp / secure-input.js View on Github external
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 iotaledger / trinity-wallet / src / desktop / native / libs / kdbx.js View on Github external
const exportVault = async (seeds, password) => {
    const credentials = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(password));
    const db = kdbxweb.Kdbx.create(credentials, 'Trinity');

    db.upgrade();

    for (let i = 0; i < seeds.length; i++) {
        const entry = db.createEntry(db.getDefaultGroup());
        entry.fields.Title = seeds[i].title || `IOTA Seed #${i + 1}`;
        entry.fields.Seed = kdbxweb.ProtectedValue.fromString(seeds[i].seed.map((byte) => byteToChar(byte)).join(''));
    }

    const chunk = await db.save();

    return chunk;
};
github subdavis / Tusk / services / keepassService.js View on Github external
function jsonCredentialsToKdbx(jsonCreds) {
		var creds = new kdbxweb.Credentials(null, null);
		for (var key in jsonCreds)
			if (jsonCreds[key])
				creds[key] = new kdbxweb.ProtectedValue(jsonCreds[key].value, jsonCreds[key].salt);
		return creds;
	}
github keeweb / keeweb / app / scripts / views / fields / field-view.js View on Github external
}
        const left = this.valueEl.position().left;
        const width = this.$el.width() - left;
        const top = this.valueEl.height();

        const mobileActionsEl = $('<div></div>')
            .addClass('details__field-mobile-actions')
            .appendTo(this.$el)
            .css({ left, top, width });

        const actions = [];
        if (this.value) {
            actions.push({ name: 'copy', icon: 'clipboard' });
        }
        actions.push({ name: 'edit', icon: 'pencil' });
        if (this.value instanceof kdbxweb.ProtectedValue) {
            actions.push({ name: 'reveal', icon: 'eye' });
        }
        if (this.model.canGen) {
            actions.push({ name: 'generate', icon: 'bolt' });
        }
        for (const action of actions) {
            $('<div></div>')
                .addClass(`details__field-mobile-action fa fa-${action.icon}`)
                .appendTo(mobileActionsEl)
                .click(() =&gt; this.doMobileAction(action.name));
        }

        this.mobileActionsEl = mobileActionsEl;
    }