UNPKG

iocane

Version:
29 lines (28 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unpackEncryptedText = exports.packEncryptedText = void 0; var symbols_1 = require("../symbols"); var PBKDF2_ROUND_DEFAULT = 1000; function packEncryptedText(encryptedComponents) { var content = encryptedComponents.content, iv = encryptedComponents.iv, salt = encryptedComponents.salt, auth = encryptedComponents.auth, rounds = encryptedComponents.rounds, method = encryptedComponents.method; return [content, iv, salt, auth, rounds, method].join("$"); } exports.packEncryptedText = packEncryptedText; function unpackEncryptedText(encryptedContent) { var _a = encryptedContent.split("$"), content = _a[0], iv = _a[1], salt = _a[2], auth = _a[3], roundsRaw = _a[4], methodRaw = _a[5]; // iocane was originally part of Buttercup's core package and used defaults from that originally. // There will be 4 components for pre 0.15.0 archives, and 5 in newer archives. The 5th component // is the pbkdf2 round count, which is optional: var rounds = roundsRaw ? parseInt(roundsRaw, 10) : PBKDF2_ROUND_DEFAULT; // Originally only "cbc" was supported, but GCM was added in version 1 var method = methodRaw || symbols_1.ALGO_DEFAULT; return { content: content, iv: iv, salt: salt, auth: auth, rounds: rounds, method: method }; } exports.unpackEncryptedText = unpackEncryptedText;