easy_aes 0.0.1 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/lib/easy_aes.rb +51 -28
- data/lib/easy_aes/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af0efdd2c2bc19fd52f2f77075e594b310137827
|
4
|
+
data.tar.gz: 66428cc7f2d0aac625162cf94e7e0fa8065fc97b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca35b4f769651e22ebff80ca1c0307e2b8c8eebfaee9f2fa1b31c250fa72d1caee5ca54b91e9033a88040f3b160cb495adbe087b9daea98b4403122452f808ee
|
7
|
+
data.tar.gz: 74c92c7c278656b480406657184ea6a7e417dee48d7f3b692e88fa1237830e6d32290b6fc0ac70bc7d4e614edb313a292c79800fe647a81fc7bd1abde3ebc11e
|
data/README.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# EasyAes
|
2
2
|
|
3
|
-
|
3
|
+
EasyAES is a simple gem for easily using encryption and deryption with AES algorithm.
|
4
|
+
|
5
|
+
EasyAES can generate the secret with:
|
6
|
+
```
|
7
|
+
EasyAES.generate_secret
|
8
|
+
```
|
9
|
+
|
10
|
+
Data is encrypted with `EasyAES.encrypt data, secret`
|
11
|
+
and decrypted with `EasyAES.derypt data, secret`
|
12
|
+
|
13
|
+
Generated secret and encrypted data is `Base64` encoded so it can easily be stored to a file or database.
|
14
|
+
Also the secret that both `encrypt` and `decrypt` are getting are `Base64` encoded `yaml` serialization of array [key, iv] (`generate_secret` generates in that that format already)
|
4
15
|
|
5
16
|
## Installation
|
6
17
|
|
data/lib/easy_aes.rb
CHANGED
@@ -1,34 +1,57 @@
|
|
1
|
-
require
|
1
|
+
require 'easy_aes/version'
|
2
2
|
|
3
3
|
require 'openssl'
|
4
4
|
require 'base64'
|
5
|
+
require 'yaml'
|
5
6
|
|
6
7
|
class EasyAES
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
8
|
+
|
9
|
+
def self.generate_secret
|
10
|
+
cipher = OpenSSL::Cipher::Cipher.new 'aes-256-cbc'
|
11
|
+
serialize [cipher.random_key, cipher.random_iv]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.serialize data
|
15
|
+
Base64.encode64 data.to_yaml
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.deserialize data
|
19
|
+
YAML.load Base64.decode64(data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.encrypt data, secret
|
23
|
+
# create the cipher for encrypting
|
24
|
+
cipher = OpenSSL::Cipher::Cipher.new 'aes-256-cbc'
|
25
|
+
cipher.encrypt
|
26
|
+
|
27
|
+
# load secret into the cipher
|
28
|
+
secret = deserialize secret
|
29
|
+
cipher.key = secret.first
|
30
|
+
cipher.iv = secret.last
|
31
|
+
|
32
|
+
# encrypt the message
|
33
|
+
encrypted = cipher.update data
|
34
|
+
encrypted << cipher.final
|
35
|
+
|
36
|
+
serialize encrypted
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.decrypt data, secret
|
40
|
+
# create the cipher for encrypting
|
41
|
+
cipher = OpenSSL::Cipher::Cipher.new 'aes-256-cbc'
|
42
|
+
cipher.decrypt
|
43
|
+
|
44
|
+
# load secret into the cipher
|
45
|
+
secret = deserialize secret
|
46
|
+
cipher.key = secret.first
|
47
|
+
cipher.iv = secret.last
|
48
|
+
|
49
|
+
# decrypt the message
|
50
|
+
data = deserialize data
|
51
|
+
decrypted = cipher.update data
|
52
|
+
decrypted << cipher.final
|
53
|
+
|
54
|
+
decrypted
|
55
|
+
end
|
56
|
+
|
34
57
|
end
|
data/lib/easy_aes/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_aes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 7sedam7
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.4.5.1
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Gem that allows easy aes algorithm usage
|