blob: 93d2b78fba8c04af97b7f8a240365398581c6a6a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
local helpers = require("encrypt.helpers")
---@return string[]
---@param lines string | string[]
---@param password string
local function encrypt_lines(lines, password)
return vim.fn.systemlist(
"openssl enc -aes-256-cbc -pbkdf2 -salt -in - -out - -k " .. vim.fn.shellescape(password) .. " | base64",
lines
)
end
local function encrypt()
local password = helpers.getPassword()
local buf_lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
local encrypted_lines = encrypt_lines(buf_lines, password)
table.insert(encrypted_lines, 1, helpers.ENCRYPTED_PREFIX)
vim.fn.writefile(encrypted_lines, vim.fn.expand("%"))
vim.bo.modified = false
print("Encrypted " .. vim.fn.expand("%:t"))
end
return encrypt
|