MySecret 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTING.md +28 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +19 -0
- data/LICENSE.txt +21 -0
- data/MySecret.gemspec +39 -0
- data/README.md +93 -0
- data/Rakefile +4 -0
- data/bin/MySecret +5 -0
- data/build.sh +9 -0
- data/lib/MySecret/base64.rb +11 -0
- data/lib/MySecret/constants.rb +9 -0
- data/lib/MySecret/cryptography.rb +28 -0
- data/lib/MySecret/display.rb +35 -0
- data/lib/MySecret/file.rb +32 -0
- data/lib/MySecret/main.rb +56 -0
- data/lib/MySecret/note.rb +73 -0
- data/lib/MySecret/system.rb +45 -0
- data/lib/MySecret/version.rb +5 -0
- data/lib/MySecret.rb +34 -0
- data/sig/MySecret.rbs +4 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2999966a6db5796d756c21f387ec62be8698832be45725cad537ec5e0ae818ed
|
4
|
+
data.tar.gz: c630f92721e781dd8680a898375cc12658c484d9f60f908b8747594d7f438743
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2297cf9b7d8e55ad5ff91705cb6760c00ae8812f34693539395c9adb39e301cf901e893eb572f14d847f0cad1bbcbf45053c14d18d580eae6b31d528b6495cb6
|
7
|
+
data.tar.gz: be1898ee7550fa9bb7833661e0d6dc20a3f0dd03bde2fd1c89ca88d868ae4c48ef9ac172acdf7db611e343e0cc51f95929d516ebc8b4077b5550cc33a4e34056
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at felipe.tenorio123456@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Contributing to MySecret
|
2
|
+
First off, thanks for taking the time to contribute! ❤️
|
3
|
+
|
4
|
+
All types of contributions are encouraged and valued. See the Table of Contents for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. 🎉
|
5
|
+
|
6
|
+
## Reporting Bugs
|
7
|
+
First of all, if you find a bug and want to help us solving it, certify these things first:
|
8
|
+
|
9
|
+
- Make sure that you are using the latest version.
|
10
|
+
- Determine if your bug is really a bug and not an error on your side.
|
11
|
+
- See if other users have experienced (or solved) the same issue you are having by checking the [repository issues](https://github.com/FelipeFTN/MySecret/issues).
|
12
|
+
- Collect information about the bug:
|
13
|
+
- OS, Platform and Version (Windows, Linux, MacOS, x86, ARM).
|
14
|
+
- Ruby version.
|
15
|
+
- Possibly your input and the output.
|
16
|
+
- A way to reproduce the issue.
|
17
|
+
|
18
|
+
After following these steps, you can:
|
19
|
+
|
20
|
+
- Open an [Issue](https://github.com/FelipeFTN/MySecret/issues/new).
|
21
|
+
- Explain the behaviour you would expect and the actual behaviour.
|
22
|
+
- Provide as much context as possible and the actual behavior.
|
23
|
+
- Provide the information you collected in the previously.
|
24
|
+
|
25
|
+
## Code Contribution
|
26
|
+
If you have the necessary skills to improve MySecret, please feel free to [fork](https://github.com/FelipeFTN/MySecret/fork) the repository and start doing what you do best.
|
27
|
+
|
28
|
+
After forking the repo, adding your contribution, just open a pull request and wait for review.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 FelipeFTN
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/MySecret.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/MySecret/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "MySecret"
|
7
|
+
spec.version = MySecret::VERSION
|
8
|
+
spec.authors = ["FelipeFTN"]
|
9
|
+
spec.email = ["felipe.tenorio123456@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Keep your notes safe! "
|
12
|
+
spec.description = "MySecret is a secure note manager. It allows you to safe your notes with password, encryption and encoding."
|
13
|
+
spec.homepage = "https://github.com/FelipeFTN/MySecret"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/FelipeFTN/MySecret"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/FelipeFTN/MySecret/blob/master/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "bin"
|
31
|
+
spec.executables = [ "MySecret" ]
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
# MySecret
|
3
|
+
MySecret is a secure note manager.<br>
|
4
|
+
It allows you to safe your notes with password, encryption and encoding.
|
5
|
+
MySecret uses tree layers of security:
|
6
|
+
- AES-256 Encryption
|
7
|
+
- Base64 Encoding
|
8
|
+
- SHA-256 Hashing
|
9
|
+
|
10
|
+
## Requirements
|
11
|
+
- Ruby
|
12
|
+
- Gem (this usually comes with Ruby)
|
13
|
+
- Secrets (You want to save something into your notes, right?)
|
14
|
+
|
15
|
+
## Usage/Examples
|
16
|
+
MySecret's main menu looks like this, you can **create a new encrypted note**, **read an encrypted note**, **edit an encrypted note**, **delete a note** **encrypt a raw file**, **decrypt a encrypted file**, **change file password** or **exit**.
|
17
|
+
```bash
|
18
|
+
$ ruby ~/MySecret/main.rb
|
19
|
+
|
20
|
+
notes: 0; 1; 2; 3; 4; 5; 6;
|
21
|
+
========== MySecret ==========
|
22
|
+
[1] Create new note
|
23
|
+
[2] Read a note
|
24
|
+
[3] Edit a note
|
25
|
+
[4] Delete a note
|
26
|
+
[5] Encrypt a note
|
27
|
+
[6] Decrypt a note
|
28
|
+
[7] Change secret key
|
29
|
+
[8] Change text editor
|
30
|
+
[0] Exit
|
31
|
+
> | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 |
|
32
|
+
```
|
33
|
+
After that, it will ask you for a **secret key**, which is a file **password**. (MySecret will hash this password using **SHA-256**)<br>
|
34
|
+
If it's your first time running **MySecret** you need to select a text editor to write down your file, select one of the options, and your text editor will magically open and you can **write all your notes safelly**.
|
35
|
+
Your default editor will be saved at a configuration file located at _home/.config/MySecret_, you can delete it to reset your preference and choose another. ```configuration file: editor.config```
|
36
|
+
```bash
|
37
|
+
file name: MySecret
|
38
|
+
$ secret key: MyPassword
|
39
|
+
=================================
|
40
|
+
Select your favorite text editor:
|
41
|
+
[0] Nano
|
42
|
+
[1] VI
|
43
|
+
[2] VIM
|
44
|
+
[3] NeoVim
|
45
|
+
[4] Emacs
|
46
|
+
[5] Notepad
|
47
|
+
> | 0 | 1 | 2 | 3 |
|
48
|
+
```
|
49
|
+
After saving and exiting from your file, your note will be automatically encoded and encrypted, and **you can access it from the MySecret's menu to decrypt and read it.**
|
50
|
+
|
51
|
+
https://user-images.githubusercontent.com/80127749/211131154-c7833698-8285-49fa-a6fd-4dc902a7433b.mov
|
52
|
+
|
53
|
+
## Installation
|
54
|
+
## Ruby Gem install (Recommended)
|
55
|
+
MySecret has a simple instalation in all operating systems.<br>
|
56
|
+
In order to install MySecret using gem, just run:
|
57
|
+
```bash
|
58
|
+
$ gem install MySecret
|
59
|
+
```
|
60
|
+
Didn't got any errors? So you are good to go!
|
61
|
+
```bash
|
62
|
+
$ MySecret
|
63
|
+
```
|
64
|
+
In case you have any problems with your installation or usage, please, let us know by openning an [issue](https://github.com/FelipeFTN/MySecret/issues/new) 😉
|
65
|
+
Warning: Please, make sure you have Gem set in your `$PATH`, do this, in case you have some error while executing MySecret, and restart your terminal:
|
66
|
+
```bash
|
67
|
+
# Ruby Gem
|
68
|
+
$ export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
|
69
|
+
$ export PATH="$PATH:$GEM_HOME/bin"
|
70
|
+
```
|
71
|
+
## Building from source
|
72
|
+
First of all, MySecret's latest release from [Releases page](https://github.com/FelipeFTN/MySecret/releases); or just clone the master branch into your machine.<br>
|
73
|
+
then run MySecret's Build file: `build.sh`<br>
|
74
|
+
```bash
|
75
|
+
$ sh build.sh
|
76
|
+
```
|
77
|
+
You should be ready to go! Now, just run: `MySecret` into your terminal.
|
78
|
+
Warning: Please, make sure you have Gem set in your `$PATH`, do this, in case you have some error while executing MySecret, and restart your terminal:
|
79
|
+
```bash
|
80
|
+
# Ruby Gem
|
81
|
+
$ export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
|
82
|
+
$ export PATH="$PATH:$GEM_HOME/bin"
|
83
|
+
```
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
If you want to contribute to improve MySecret, please read [CONTRIBUTING.md](https://github.com/FelipeFTN/MySecret/blob/master/CONTRIBUTING.md).
|
88
|
+
|
89
|
+
> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:
|
90
|
+
> - Star the project
|
91
|
+
> - Tweet about it
|
92
|
+
> - Refer this project in your project's readme
|
93
|
+
> - Mention the project at local meetups and tell your friends/colleagues
|
data/Rakefile
ADDED
data/bin/MySecret
ADDED
data/build.sh
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "constants"
|
2
|
+
|
3
|
+
require "openssl"
|
4
|
+
require "digest"
|
5
|
+
|
6
|
+
def encrypt(data, secret_key)
|
7
|
+
aes = OpenSSL::Cipher.new("aes-256-cbc")
|
8
|
+
aes.encrypt
|
9
|
+
aes.iv = hasher(IV_ALGORITHM, 16)
|
10
|
+
aes.key = secret_key
|
11
|
+
|
12
|
+
return aes.update(data) + aes.final
|
13
|
+
end
|
14
|
+
|
15
|
+
def decrypt(data, secret_key)
|
16
|
+
aes = OpenSSL::Cipher.new("aes-256-cbc")
|
17
|
+
aes.decrypt
|
18
|
+
aes.iv = hasher(IV_ALGORITHM, 16)
|
19
|
+
aes.key = secret_key
|
20
|
+
|
21
|
+
return aes.update(data) + aes.final
|
22
|
+
end
|
23
|
+
|
24
|
+
def hasher(secret, limit_chars)
|
25
|
+
secret = Digest::SHA256.hexdigest secret
|
26
|
+
secret = secret[0, limit_chars]
|
27
|
+
return secret
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "constants"
|
2
|
+
|
3
|
+
def display_notes()
|
4
|
+
notes = Dir.glob("#{NOTES_DIRECTORY}/*")
|
5
|
+
print "notes: "
|
6
|
+
notes.each do |note|
|
7
|
+
print "#{note.gsub! "#{NOTES_DIRECTORY}/", ""}; "
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def display_menu()
|
12
|
+
puts "\n========== MySecret =========="
|
13
|
+
puts "[1] Create new note"
|
14
|
+
puts "[2] Read a note"
|
15
|
+
puts "[3] Edit a note"
|
16
|
+
puts "[4] Delete a note"
|
17
|
+
puts "[5] Encrypt an existing note"
|
18
|
+
puts "[6] Decrypt an existing note"
|
19
|
+
puts "[7] Change secret key"
|
20
|
+
puts "[8] Change text editor"
|
21
|
+
puts "[0] Exit"
|
22
|
+
print "> "
|
23
|
+
end
|
24
|
+
|
25
|
+
def display_text_editor()
|
26
|
+
puts "================================="
|
27
|
+
puts "Select your favorite text editor:"
|
28
|
+
puts "[0] Nano"
|
29
|
+
puts "[1] VI"
|
30
|
+
puts "[2] VIM"
|
31
|
+
puts "[3] NeoVim"
|
32
|
+
puts "[4] Emacs"
|
33
|
+
puts "[5] Notepad"
|
34
|
+
print "> "
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "constants"
|
2
|
+
|
3
|
+
|
4
|
+
def get_file()
|
5
|
+
print "file name: "
|
6
|
+
file_name = gets.chomp
|
7
|
+
file_path = "#{NOTES_DIRECTORY}/#{file_name}"
|
8
|
+
return file_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_secret_key(message = "secret key: ")
|
12
|
+
print message
|
13
|
+
secret_key = hasher(gets.chomp, 32)
|
14
|
+
return secret_key
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_file(file_path)
|
18
|
+
file = File.open(file_path)
|
19
|
+
if file
|
20
|
+
data = file.read
|
21
|
+
return data.chomp
|
22
|
+
else
|
23
|
+
puts "error: not able to access the file"
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def write_file(file_path, data)
|
29
|
+
File.open(file_path, "w") do |line|
|
30
|
+
line.puts data
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "cryptography"
|
2
|
+
require_relative "constants"
|
3
|
+
require_relative "system"
|
4
|
+
require_relative "file"
|
5
|
+
require_relative "note"
|
6
|
+
|
7
|
+
def handler(option)
|
8
|
+
if option == 1
|
9
|
+
# Get file name & secret key
|
10
|
+
file_path = get_file()
|
11
|
+
secret_key = get_secret_key()
|
12
|
+
|
13
|
+
write_note(file_path, secret_key)
|
14
|
+
elsif option == 2
|
15
|
+
# Get file name & secret key
|
16
|
+
file_path = get_file()
|
17
|
+
secret_key = get_secret_key()
|
18
|
+
|
19
|
+
read_note(file_path, secret_key)
|
20
|
+
elsif option == 3
|
21
|
+
# Get file name & secret key
|
22
|
+
file_path = get_file()
|
23
|
+
secret_key = get_secret_key()
|
24
|
+
|
25
|
+
edit_note(file_path, secret_key)
|
26
|
+
elsif option == 4
|
27
|
+
# Get file name
|
28
|
+
file_path = get_file()
|
29
|
+
secret_key = get_secret_key("deleting confirmation secret_key: ")
|
30
|
+
|
31
|
+
delete_note(file_path, secret_key)
|
32
|
+
elsif option == 5
|
33
|
+
# Get file name & secret key
|
34
|
+
file_path = get_file()
|
35
|
+
secret_key = get_secret_key()
|
36
|
+
|
37
|
+
encrypt_note(file_path, secret_key)
|
38
|
+
elsif option == 6
|
39
|
+
# Get file name & secret key
|
40
|
+
file_path = get_file()
|
41
|
+
secret_key = get_secret_key()
|
42
|
+
|
43
|
+
decrypt_note(file_path, secret_key)
|
44
|
+
elsif option == 7
|
45
|
+
# Get file name & secret key
|
46
|
+
file_path = get_file()
|
47
|
+
secret_key = get_secret_key()
|
48
|
+
new_secret_key = get_secret_key("new secret key: ")
|
49
|
+
|
50
|
+
change_secret(file_path, secret_key, new_secret_key)
|
51
|
+
elsif option == 8
|
52
|
+
execute("rm -f #{EDITOR_PATH}")
|
53
|
+
|
54
|
+
get_text_editor()
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require_relative "cryptography"
|
2
|
+
require_relative "base64"
|
3
|
+
require_relative "system"
|
4
|
+
require_relative "file"
|
5
|
+
|
6
|
+
def write_note(file_path, secret_key)
|
7
|
+
editor = get_text_editor()
|
8
|
+
execute("#{editor} #{file_path}")
|
9
|
+
|
10
|
+
data = read_file(file_path)
|
11
|
+
encrypted_data = encrypt(data, secret_key)
|
12
|
+
encoded_data = encode(encrypted_data)
|
13
|
+
|
14
|
+
write_file(file_path, encoded_data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_note(file_path, secret_key)
|
18
|
+
data = read_file(file_path)
|
19
|
+
decoded_data = decode(data)
|
20
|
+
decrypted_data = decrypt(decoded_data, secret_key)
|
21
|
+
|
22
|
+
temp_file = "#{file_path}.temp"
|
23
|
+
write_file(temp_file, decrypted_data)
|
24
|
+
|
25
|
+
editor = get_text_editor()
|
26
|
+
execute("#{editor} #{temp_file}")
|
27
|
+
execute("rm #{temp_file}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit_note(file_path, secret_key)
|
31
|
+
data = read_file(file_path)
|
32
|
+
decoded_data = decode(data)
|
33
|
+
decrypted_data = decrypt(decoded_data, secret_key)
|
34
|
+
|
35
|
+
temp_file = "#{file_path}.temp"
|
36
|
+
write_file(temp_file, decrypted_data)
|
37
|
+
|
38
|
+
editor = get_text_editor()
|
39
|
+
execute("#{editor} #{temp_file}")
|
40
|
+
|
41
|
+
encrypt_note(temp_file, secret_key)
|
42
|
+
|
43
|
+
execute("rm #{file_path}")
|
44
|
+
execute("mv #{temp_file} #{file_path}")
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete_note(file_path, secret_key)
|
48
|
+
decrypt_note(file_path, secret_key)
|
49
|
+
encrypt_note(file_path, secret_key)
|
50
|
+
|
51
|
+
execute("rm #{file_path}")
|
52
|
+
end
|
53
|
+
|
54
|
+
def encrypt_note(file_path, secret_key)
|
55
|
+
data = read_file(file_path)
|
56
|
+
encrypted_data = encrypt(data, secret_key)
|
57
|
+
encoded_data = encode(encrypted_data)
|
58
|
+
|
59
|
+
write_file(file_path, encoded_data)
|
60
|
+
end
|
61
|
+
|
62
|
+
def decrypt_note(file_path, secret_key)
|
63
|
+
data = read_file(file_path)
|
64
|
+
decoded_data = decode(data)
|
65
|
+
decrypted_data = decrypt(decoded_data, secret_key)
|
66
|
+
|
67
|
+
write_file(file_path, decrypted_data)
|
68
|
+
end
|
69
|
+
|
70
|
+
def change_secret(file_path, old_secret_key, new_secret_key)
|
71
|
+
decrypt_note(file_path, old_secret_key)
|
72
|
+
encrypt_note(file_path, new_secret_key)
|
73
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative "constants"
|
2
|
+
require_relative "display"
|
3
|
+
require_relative "file"
|
4
|
+
|
5
|
+
def get_text_editor()
|
6
|
+
text_editors = ["nano", "vi", "vim", "nvim", "emacs", "notepad"]
|
7
|
+
if File.file?(EDITOR_PATH)
|
8
|
+
editor = read_file(EDITOR_PATH).chomp
|
9
|
+
if text_editors.include?(editor)
|
10
|
+
return editor
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
display_text_editor()
|
15
|
+
text_editor = gets.chomp.to_i
|
16
|
+
write_file(EDITOR_PATH, text_editors[text_editor])
|
17
|
+
|
18
|
+
return text_editors[text_editor]
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute(command, pause=false)
|
22
|
+
system(command)
|
23
|
+
|
24
|
+
if pause
|
25
|
+
print "\nPress enter to proceed"
|
26
|
+
gets
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_options(option)
|
31
|
+
valid_options = [0, 1, 2, 3, 4, 5, 6, 7, 8]
|
32
|
+
is_valid = valid_options.include? option
|
33
|
+
if !is_valid
|
34
|
+
puts "error: invalid option"
|
35
|
+
return false
|
36
|
+
elsif option == 0
|
37
|
+
return false
|
38
|
+
end
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
|
42
|
+
def options_menu()
|
43
|
+
display_menu()
|
44
|
+
option = gets.chomp.to_i
|
45
|
+
end
|
data/lib/MySecret.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "MySecret/constants"
|
4
|
+
require_relative "MySecret/version"
|
5
|
+
require_relative "MySecret/display"
|
6
|
+
require_relative "MySecret/system"
|
7
|
+
require_relative "MySecret/main"
|
8
|
+
|
9
|
+
module MySecret
|
10
|
+
class Error < StandardError; end
|
11
|
+
def self.run()
|
12
|
+
# Create MySecret folder
|
13
|
+
Dir.mkdir(CONFIG_DIRECTORY) unless File.exist?(CONFIG_DIRECTORY)
|
14
|
+
Dir.mkdir(MYSECRET_DIRECTORY) unless File.exist?(MYSECRET_DIRECTORY)
|
15
|
+
Dir.mkdir(NOTES_DIRECTORY) unless File.exist?(NOTES_DIRECTORY)
|
16
|
+
|
17
|
+
while true
|
18
|
+
# List notes
|
19
|
+
display_notes()
|
20
|
+
|
21
|
+
# Display menu options
|
22
|
+
option = options_menu()
|
23
|
+
|
24
|
+
# Input Validation
|
25
|
+
validate_options(option) ? nil : return
|
26
|
+
|
27
|
+
# Handle options
|
28
|
+
handler(option)
|
29
|
+
|
30
|
+
# Clear terminal
|
31
|
+
puts `clear`
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/sig/MySecret.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: MySecret
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- FelipeFTN
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: MySecret is a secure note manager. It allows you to safe your notes with
|
14
|
+
password, encryption and encoding.
|
15
|
+
email:
|
16
|
+
- felipe.tenorio123456@gmail.com
|
17
|
+
executables:
|
18
|
+
- MySecret
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- CHANGELOG.md
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- CONTRIBUTING.md
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- LICENSE.txt
|
28
|
+
- MySecret.gemspec
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- bin/MySecret
|
32
|
+
- build.sh
|
33
|
+
- lib/MySecret.rb
|
34
|
+
- lib/MySecret/base64.rb
|
35
|
+
- lib/MySecret/constants.rb
|
36
|
+
- lib/MySecret/cryptography.rb
|
37
|
+
- lib/MySecret/display.rb
|
38
|
+
- lib/MySecret/file.rb
|
39
|
+
- lib/MySecret/main.rb
|
40
|
+
- lib/MySecret/note.rb
|
41
|
+
- lib/MySecret/system.rb
|
42
|
+
- lib/MySecret/version.rb
|
43
|
+
- sig/MySecret.rbs
|
44
|
+
homepage: https://github.com/FelipeFTN/MySecret
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata:
|
48
|
+
allowed_push_host: https://rubygems.org
|
49
|
+
homepage_uri: https://github.com/FelipeFTN/MySecret
|
50
|
+
source_code_uri: https://github.com/FelipeFTN/MySecret
|
51
|
+
changelog_uri: https://github.com/FelipeFTN/MySecret/blob/master/CHANGELOG.md
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.6.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.3.25
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Keep your notes safe!
|
71
|
+
test_files: []
|