aboutsummaryrefslogtreecommitdiff
path: root/lua/encrypt/encrypt.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/encrypt/encrypt.lua')
-rw-r--r--lua/encrypt/encrypt.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/lua/encrypt/encrypt.lua b/lua/encrypt/encrypt.lua
new file mode 100644
index 0000000..5cdf8a9
--- /dev/null
+++ b/lua/encrypt/encrypt.lua
@@ -0,0 +1,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 " .. 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