Skip to content

Instantly share code, notes, and snippets.

@AlexAvlonitis
Last active March 31, 2021 20:45
Show Gist options
  • Save AlexAvlonitis/4df0b52bbb1f6122e93d to your computer and use it in GitHub Desktop.
Save AlexAvlonitis/4df0b52bbb1f6122e93d to your computer and use it in GitHub Desktop.
Encrypt files with Ruby and OpenSSL
# Ruby script encrypts files with OpenSSL
# https://github.com/alexavlonitis
i = 1
while i != 0 do
puts "---MENU---"
puts "(1) to Encrypt"
puts "(2) to Decrypt"
puts "(3) to Exit"
print ": "
option = gets.chomp
c = 1
if option == "1"
while c != 0 do
puts "Type the filename you want to Encrypt, OR 'exit' to go back to menu"
print ": "
filename = gets.chomp
filename == "exit" ? c = 0 : system("openssl aes-256-cbc -a -salt -in #{filename} -out #{filename}.enc")
end
elsif option == "2"
while c != 0 do
puts "Type the filename you want to Decrypt, OR 'exit' to go back to menu"
print ": "
filename = gets.chomp
name = filename.match(/^\w+/)
extension = filename.match(/(?<=\.)(.*?)(?=\.)/)
filename == "exit" ? c = 0 : system("openssl aes-256-cbc -d -a -in #{filename} -out #{name}.#{extension} ")
end
elsif option == "3"
i = 0
else
puts "wrong input, Try again."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment