crypto_cipher 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/crypto_cipher.gemspec +30 -0
- data/example/config/private_cipher.key +2 -0
- data/example/config/private_key.pem +28 -0
- data/example/config/public_key.pem +9 -0
- data/lib/cipher/crypto_cipher_aes.rb +114 -0
- data/lib/cipher/crypto_cipher_bs64.rb +15 -0
- data/lib/crypto_cipher.rb +3 -0
- data/lib/crypto_cipher/version.rb +3 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 231954e0a8d43513a6d52862966f63898a0fc4d0873a16f7a1c100518dce290d
|
4
|
+
data.tar.gz: c8a77d1721dfa3062d0b5c0d9dbb80159a51fc90c8d973d58813f80e2f99fc45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 153aeac7da8114f442f6b0d8771146e94b0cff3dd0541040ffae481609b145317bcd8e4f6254d6248a87831fb73a93720b4289ad288664babc69d1ea116c3954
|
7
|
+
data.tar.gz: 79beefa1157eb13af862dde494f65126310703f1661d1f3ce03662db96b496a6bace1a16f47d5474a9a50c7c456a96bcc1d8d88188f354a5afe3198d46474541
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at esaud17@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
crypto_cipher (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.3)
|
10
|
+
rake (12.3.3)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.2)
|
16
|
+
rspec-support (~> 3.9.3)
|
17
|
+
rspec-expectations (3.9.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
crypto_cipher!
|
30
|
+
rake (~> 12.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 esaud17
|
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/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# CryptoCipher
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/crypto_cipher`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'crypto_cipher'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install crypto_cipher
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Generate Private.key
|
26
|
+
|
27
|
+
$ openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
|
28
|
+
|
29
|
+
Generate Public.Key
|
30
|
+
|
31
|
+
$ openssl rsa -pubout -in private_key.pem -out public_key.pem
|
32
|
+
|
33
|
+
Use AES256
|
34
|
+
|
35
|
+
cipher = CryptoCipher::CryptoAES256.new('./example/config/public_key.pem','./example/config/private_key.pem','./example/config/private_cipher.key')
|
36
|
+
|
37
|
+
plan_text = "loremipsu"
|
38
|
+
encryt_text = cipher.encrypt(plan_text)
|
39
|
+
decrypt_text = cipher.decrypt(encryt_text)
|
40
|
+
|
41
|
+
Use Base64
|
42
|
+
|
43
|
+
cipher = CryptoCipher::CryptoBS64.new
|
44
|
+
|
45
|
+
plan_text = "loremipsu"
|
46
|
+
encryt_text = cipher.encode(plan_text)
|
47
|
+
decrypt_text = cipher.decode(encryt_text)
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/crypto_cipher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/crypto_cipher/blob/master/CODE_OF_CONDUCT.md).
|
58
|
+
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
63
|
+
|
64
|
+
## Code of Conduct
|
65
|
+
|
66
|
+
Everyone interacting in the CryptoCipher project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/crypto_cipher/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "crypto_cipher"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'lib/crypto_cipher/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
|
5
|
+
spec.name = "crypto_cipher"
|
6
|
+
spec.version = CryptoCipher::VERSION
|
7
|
+
spec.authors = ["esaud17"]
|
8
|
+
spec.email = ["esaud17@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = %q{Cipher easy encrypt and decrypt Aes256, Base64 Encode and Decode.}
|
11
|
+
spec.description = %q{Cipher easy encrypt and decrypt Aes256, Base64 Encode and Decode.}
|
12
|
+
spec.homepage = "https://github.com/Esaud17/crypto_cipher.git"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
15
|
+
|
16
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/Esaud17/crypto_cipher.git"
|
20
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
-----BEGIN PRIVATE KEY-----
|
2
|
+
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC1MaHEHBeKyexM
|
3
|
+
x3umU7RnrX0ds/aopZY9OoOz/VyE8OCqyYFPw4j0+l7+cxRJHb2GH7xAemQIikbx
|
4
|
+
7LRfTa1H6nYEQqbTMv2559Q3DLM0fUPEyByepE/cHY4F+XChQ/Lcjcoq/o8pI3jP
|
5
|
+
fz7g/MhLdbVtp3r22Upv8EsCs2wPfXV4jCWeXHmmBFOK4oTtelMP/Yqc4B3rGsrP
|
6
|
+
Gc29xPb3vOTwmrQNNDn3LghnHsTpTUw9ao/daq3vKTOpgOoUN7ZuVJD7lsIU0zBb
|
7
|
+
nbUzetHHJityY8+Cjq0j8kRlReVs3mIyD/6uWV6ltzUy5zzjwi67RD8vHifCVw9f
|
8
|
+
5Tb3eCDdAgMBAAECggEBAK8XkPyTMOS7D496TTCDPpfZfEgRuc9qg+4S92Yc9SS6
|
9
|
+
KEChjEXp7BTfRKCZ0AZ/qL9NN3sPSk8+YCQz2nEl/Ma7+ONRDSiV472cGuQ/b4TP
|
10
|
+
b4de4Nkkas+H99AqJP6RTMR4d95oMytLzdilW7vKSjsxOesGprqXa2kUSUgI3elw
|
11
|
+
b2uLLKgUErOxcu4KmoJowfH4ngehqvpOOSYuAXdeJ5XiaAkgHtgTAiTxxufRw2bZ
|
12
|
+
2u7AlbOj0PABkYBu6f7RC4FRIi2bCYqjROtlFblRHNp0A1wkabkx59+M8kKpJVgT
|
13
|
+
2sBONbA3bmpeUGuG+dfkOMdJIKBv91VSKHqBKd/TkkECgYEA6M8FTlvSsr15uLgn
|
14
|
+
IR4WNkhyzLwb+a5Re5Oid9//98YVWAUi5wTjKb6RQnW5BCPXlQsKtr6DpHSawBR9
|
15
|
+
1SKimdEgUJWNpBI1jFdTtDOirfKcI1DrbRa+tCSvGqwQByYFev1td/CnW8Q+Rj+w
|
16
|
+
5M5jD9B+3xpE+56FnxYInr4t6ykCgYEAxz5auOGA4XejjSuXlK+MdAzXV/hbvf/O
|
17
|
+
o7T/cRLYwHkjjY1i7S8uGsFv5WCuBlQ8zPdbx5vFikBkvq4lPumAcCSglGMKFS7g
|
18
|
+
OkA4cIZ7gWlhxWIj4mcLQMIwDToKn5+7pksdRn+ugg+bxFQXyWTsky8oyMufliP1
|
19
|
+
JjbjdPqWcpUCgYAPhvcwobksyKxcoJOjhtEub6iQdR9ciL7Qgik824jD6sczpqwM
|
20
|
+
QmwwNZCUoStk1ksjmqftRkmbZ1eG5hb6ZyP3JFaGaWMYBUrjAFQJ2cPI3DyDsnrx
|
21
|
+
PKodc7DmE4HCKEwHRu3NKRTQbwdEQi03JXi/7kT39lWRfqIk2SBcDg0b+QKBgFHe
|
22
|
+
ZEbNmjiLAXAzdlCJJaxVznJ+Qaw7nXwVFlUvClNkM2CptPmCxm4GB+V3qWo+WNFb
|
23
|
+
3qGRd0UMmpjjU7ibF8R8uGLgozb7EPW+h7Js//i4BY2meto/vxb38+irbcwTRXba
|
24
|
+
LIhYVKtqoHW2nCOLzc3Yteh0CvoVglkWerYJdaJVAoGAfCyCmaIaSQB0dkH76YWI
|
25
|
+
ByRwzdvGrQnz85J+PFcANG35SvdGpPwVp41iJh3qNSiTe+cbjpuac6Aveze/+BQY
|
26
|
+
IsvuL7SBESH1QaxZE1RoGwm5vOPX3kKwAkp0NEqvBDK7pMLBrjYeXN773Ava4uPv
|
27
|
+
kBLDOPZMcAbIDLt9TXzLoF4=
|
28
|
+
-----END PRIVATE KEY-----
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-----BEGIN PUBLIC KEY-----
|
2
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtTGhxBwXisnsTMd7plO0
|
3
|
+
Z619HbP2qKWWPTqDs/1chPDgqsmBT8OI9Ppe/nMUSR29hh+8QHpkCIpG8ey0X02t
|
4
|
+
R+p2BEKm0zL9uefUNwyzNH1DxMgcnqRP3B2OBflwoUPy3I3KKv6PKSN4z38+4PzI
|
5
|
+
S3W1bad69tlKb/BLArNsD311eIwlnlx5pgRTiuKE7XpTD/2KnOAd6xrKzxnNvcT2
|
6
|
+
97zk8Jq0DTQ59y4IZx7E6U1MPWqP3Wqt7ykzqYDqFDe2blSQ+5bCFNMwW521M3rR
|
7
|
+
xyYrcmPPgo6tI/JEZUXlbN5iMg/+rllepbc1Muc848Iuu0Q/Lx4nwlcPX+U293gg
|
8
|
+
3QIDAQAB
|
9
|
+
-----END PUBLIC KEY-----
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require "base64"
|
3
|
+
|
4
|
+
module CryptoCipher
|
5
|
+
class CryptoAES256
|
6
|
+
|
7
|
+
attr_accessor :cipher
|
8
|
+
attr_accessor :random_key
|
9
|
+
attr_accessor :random_iv
|
10
|
+
|
11
|
+
attr_accessor :private_cipher
|
12
|
+
attr_accessor :public_key
|
13
|
+
attr_accessor :private_key
|
14
|
+
|
15
|
+
def initialize(public_key_file, private_key_file, private_cipher_file = './config/private_cipher.key')
|
16
|
+
|
17
|
+
@cipher = OpenSSL::Cipher.new('aes256')
|
18
|
+
|
19
|
+
@private_cipher = private_cipher_file
|
20
|
+
|
21
|
+
@public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
|
22
|
+
@private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file))
|
23
|
+
|
24
|
+
if exist_rsa_keys
|
25
|
+
puts 'create values'
|
26
|
+
@cipher.encrypt
|
27
|
+
|
28
|
+
@random_key = @cipher.random_key
|
29
|
+
@random_iv = @cipher.random_iv
|
30
|
+
|
31
|
+
create_key_iv @random_key, @random_iv
|
32
|
+
else
|
33
|
+
rsa = get_key_iv
|
34
|
+
@random_key = rsa[:random_key]
|
35
|
+
@random_iv = rsa[:random_iv]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
:cipher
|
42
|
+
:random_key
|
43
|
+
:random_iv
|
44
|
+
|
45
|
+
:private_cipher
|
46
|
+
:public_key
|
47
|
+
:private_key
|
48
|
+
|
49
|
+
def exist_rsa_keys
|
50
|
+
!File.exist? @private_cipher
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_key_iv
|
54
|
+
begin
|
55
|
+
line_num = 0
|
56
|
+
rsa_keys = {random_key: nil, random_iv: nil}
|
57
|
+
text = File.open(@private_cipher).read
|
58
|
+
text.each_line do |line|
|
59
|
+
if line_num ==0
|
60
|
+
rsa_keys[:random_key] = Base64.decode64(line)
|
61
|
+
line_num += 1
|
62
|
+
elsif line_num == 1
|
63
|
+
rsa_keys[:random_iv] = Base64.decode64(line)
|
64
|
+
line_num += 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
return rsa_keys
|
68
|
+
rescue
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_key_iv(random_key, random_iv)
|
74
|
+
begin
|
75
|
+
if exist_rsa_keys
|
76
|
+
rsa = File.new(@private_cipher,'w:UTF-8')
|
77
|
+
rsa.puts Base64.strict_encode64(random_key)
|
78
|
+
rsa.puts Base64.strict_encode64(random_iv)
|
79
|
+
rsa.close
|
80
|
+
end
|
81
|
+
return true
|
82
|
+
rescue
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
public
|
88
|
+
|
89
|
+
def encrypt(plain_data)
|
90
|
+
@cipher.encrypt
|
91
|
+
|
92
|
+
@cipher.key = @random_key
|
93
|
+
@cipher.iv = @random_iv
|
94
|
+
|
95
|
+
encrypted_data = @cipher.update(plain_data) + cipher.final
|
96
|
+
return Base64.strict_encode64(encrypted_data)
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def decrypt(encrypted_data)
|
101
|
+
@cipher.decrypt
|
102
|
+
|
103
|
+
encrypted_key = @public_key.public_encrypt(@random_key)
|
104
|
+
encrypted_iv = @public_key.public_encrypt(@random_iv)
|
105
|
+
|
106
|
+
@cipher.key = @private_key.private_decrypt(encrypted_key)
|
107
|
+
@cipher.iv = @private_key.private_decrypt(encrypted_iv)
|
108
|
+
|
109
|
+
decrypted_data = @cipher.update(Base64.decode64(encrypted_data)) + cipher.final
|
110
|
+
return decrypted_data
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crypto_cipher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- esaud17
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Cipher easy encrypt and decrypt Aes256, Base64 Encode and Decode.
|
14
|
+
email:
|
15
|
+
- esaud17@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- crypto_cipher.gemspec
|
32
|
+
- example/config/private_cipher.key
|
33
|
+
- example/config/private_key.pem
|
34
|
+
- example/config/public_key.pem
|
35
|
+
- lib/cipher/crypto_cipher_aes.rb
|
36
|
+
- lib/cipher/crypto_cipher_bs64.rb
|
37
|
+
- lib/crypto_cipher.rb
|
38
|
+
- lib/crypto_cipher/version.rb
|
39
|
+
homepage: https://github.com/Esaud17/crypto_cipher.git
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
homepage_uri: https://github.com/Esaud17/crypto_cipher.git
|
44
|
+
source_code_uri: https://github.com/Esaud17/crypto_cipher.git
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.3.0
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.1.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Cipher easy encrypt and decrypt Aes256, Base64 Encode and Decode.
|
64
|
+
test_files: []
|