aes_keeper 0.0.1 → 0.1.0
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/.gitignore +1 -0
- data/LICENSE.txt +1 -1
- data/README.md +9 -5
- data/Rakefile +29 -0
- data/aes_keeper.gemspec +5 -2
- data/lib/aes_keeper/aes_keeper_marshal.rb +68 -0
- data/lib/aes_keeper/aes_keeper_pure.rb +67 -0
- data/lib/aes_keeper/version.rb +2 -2
- data/lib/aes_keeper.rb +5 -65
- data/test/aes_keeper_marshal_test.rb +52 -0
- data/test/aes_keeper_pure_test.rb +55 -0
- data/test/minitest_helper.rb +9 -0
- metadata +56 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e21e5cca9b69f4f7c2b8b4293c9dccb94b5424b6
|
|
4
|
+
data.tar.gz: 5dbbb5ffb17a53f95911c39033ba98418b66cbbd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b5966c1289e8340d51ff1931a34190804f0066427c6b583d1d502488924c41d150412bc52cff7e60148fd694307ea1636b8546c29a25ff1c80e3542893ef5757
|
|
7
|
+
data.tar.gz: fbd85365c8ae110a1c85c2eee8120dc9a093bec804558217548fa2cec67644777d05c545c3bec8f4479609daeb47eca431f9e2dbfa0a773d7bd6e9bdc8404f2d
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -4,6 +4,10 @@ A database safe encryption using AES 256 CBC. Key required, Salt optional. Ret
|
|
|
4
4
|
or you can call **.to_s** to receive the encrypted data as one String. Decrypt will accept either form of the
|
|
5
5
|
{ encrypted: '', iv: '' } pair or the String result.
|
|
6
6
|
|
|
7
|
+
**NOTE:**
|
|
8
|
+
* Class object AesKeeper uses marshal which may be incompatible across platforms and Ruby versions. A benefit from this is the ability to place entire Ruby Objects in encrypted format.
|
|
9
|
+
* Please use AESKeeper::AesKeeperPure for any compatibility reasons. It needs String input.
|
|
10
|
+
|
|
7
11
|
## Installation
|
|
8
12
|
|
|
9
13
|
Add this line to your application's Gemfile:
|
|
@@ -24,7 +28,7 @@ Or install it yourself as:
|
|
|
24
28
|
|
|
25
29
|
With encryption and iv result separate:
|
|
26
30
|
```ruby
|
|
27
|
-
cipher = AesKeeper.new(key: 'some really good 32 character long key for encryption! ^_^')
|
|
31
|
+
cipher = AesKeeper.new(key: 'some really good 32+ character long key for encryption! ^_^')
|
|
28
32
|
result = cipher.encrypt("apples")
|
|
29
33
|
# => {:encrypted=>"K1E/a75/3zxNKCTXJFJZaVe8jjeHFQG+Cv1Lxntz3oM=\n", :iv=>"uQozeVXYhaeK7Rvh1na6kA==\n"}
|
|
30
34
|
cipher.decrypt(result)
|
|
@@ -33,7 +37,7 @@ cipher.decrypt(result)
|
|
|
33
37
|
|
|
34
38
|
With encryption and iv result combined:
|
|
35
39
|
```ruby
|
|
36
|
-
cipher = AesKeeper.new(key: 'some really good 32 character long key for encryption! ^_^')
|
|
40
|
+
cipher = AesKeeper.new(key: 'some really good 32+ character long key for encryption! ^_^')
|
|
37
41
|
result = cipher.encrypt("apples").to_s
|
|
38
42
|
# => "xPbb+kVIROlA5YHvSaKsYcCobgBz/TQHpJ5wP9lAuBQ=\n:WIaGiOhjFBRBVJReiA2aTA==\n"
|
|
39
43
|
cipher.decrypt(result)
|
|
@@ -43,7 +47,7 @@ cipher.decrypt(result)
|
|
|
43
47
|
You can specify a Salt as well:
|
|
44
48
|
```ruby
|
|
45
49
|
AesKeeper.new(
|
|
46
|
-
key: 'some really good 32 character long key for encryption! ^_^',
|
|
50
|
+
key: 'some really good 32+ character long key for encryption! ^_^',
|
|
47
51
|
salt: 'asdfqwerty'
|
|
48
52
|
)
|
|
49
53
|
```
|
|
@@ -53,7 +57,7 @@ AesKeeper.new(
|
|
|
53
57
|
This code can be refactored and tested. Otherwise I consider this project feature complete. It's designed
|
|
54
58
|
with assumptions for its implementation and it's met those requirements.
|
|
55
59
|
|
|
56
|
-
1. Fork it ( https://github.com/
|
|
60
|
+
1. Fork it ( https://github.com/danielpclark/aes_keeper/fork )
|
|
57
61
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
58
62
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
59
63
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
@@ -61,7 +65,7 @@ with assumptions for its implementation and it's met those requirements.
|
|
|
61
65
|
|
|
62
66
|
## License
|
|
63
67
|
|
|
64
|
-
Copyright (c) 2015 Daniel P. Clark
|
|
68
|
+
Copyright (c) 2015-2016 Daniel P. Clark
|
|
65
69
|
|
|
66
70
|
MIT License
|
|
67
71
|
|
data/Rakefile
CHANGED
|
@@ -1,2 +1,31 @@
|
|
|
1
1
|
require "bundler/gem_tasks"
|
|
2
2
|
|
|
3
|
+
begin
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
#require 'rdoc/task'
|
|
10
|
+
#
|
|
11
|
+
#RDoc::Task.new(:rdoc) do |rdoc|
|
|
12
|
+
# rdoc.rdoc_dir = 'rdoc'
|
|
13
|
+
# rdoc.title = 'MightyString'
|
|
14
|
+
# rdoc.options << '--line-numbers'
|
|
15
|
+
# rdoc.rdoc_files.include('README.rdoc')
|
|
16
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
|
17
|
+
#end
|
|
18
|
+
|
|
19
|
+
Bundler::GemHelper.install_tasks
|
|
20
|
+
|
|
21
|
+
require 'rake/testtask'
|
|
22
|
+
|
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
|
24
|
+
t.libs << 'lib'
|
|
25
|
+
t.libs << 'test'
|
|
26
|
+
t.pattern = 'test/**/*_test.rb'
|
|
27
|
+
t.verbose = false
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
task :default => :test
|
data/aes_keeper.gemspec
CHANGED
|
@@ -5,7 +5,7 @@ require 'aes_keeper/version'
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "aes_keeper"
|
|
8
|
-
spec.version =
|
|
8
|
+
spec.version = AESKeeper::VERSION
|
|
9
9
|
spec.authors = ["Daniel P. Clark"]
|
|
10
10
|
spec.email = ["6ftdan@gmail.com"]
|
|
11
11
|
spec.summary = %q{Encrypt data via AES to database worthy strings.}
|
|
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
|
|
|
20
20
|
spec.required_ruby_version = '~> 2.0'
|
|
21
21
|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.7"
|
|
23
|
-
spec.add_development_dependency "rake", "~> 10.
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.5"
|
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.8"
|
|
25
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.1.7"
|
|
26
|
+
spec.add_development_dependency "color_pound_spec_reporter", "~> 0.0.5"
|
|
24
27
|
spec.add_runtime_dependency "armor", "~> 0.0"
|
|
25
28
|
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module AESKeeper
|
|
2
|
+
class AESKeeperMarshal
|
|
3
|
+
VERSION = VERSION
|
|
4
|
+
def initialize(options = {})
|
|
5
|
+
raise ":key required!" unless options.has_key? :key
|
|
6
|
+
raise ":key needs to be at-least 32 characters!" unless options[:key].length >= 32
|
|
7
|
+
@key = key(options)
|
|
8
|
+
@cipher = OpenSSL::Cipher::AES256.new(:CBC)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def encrypt(content, options = {})
|
|
12
|
+
if (content != nil) and (content != "")
|
|
13
|
+
@cipher.encrypt
|
|
14
|
+
@cipher.key = key(options) || @key
|
|
15
|
+
iv = @cipher.random_iv
|
|
16
|
+
@cipher.iv = iv
|
|
17
|
+
encrypted = @cipher.update Marshal.dump(content)
|
|
18
|
+
encrypted << @cipher.final
|
|
19
|
+
{
|
|
20
|
+
encrypted: Base64.encode64(encrypted).encode('utf-8'), iv: Base64.encode64(iv).encode('utf-8')
|
|
21
|
+
}.tap { |i|
|
|
22
|
+
i.define_singleton_method(:to_s) { [self[:encrypted], self[:iv]].join(":") }
|
|
23
|
+
i.define_singleton_method(:to_string) { [self[:encrypted], self[:iv]].join(":") }
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
{ encrypted: '', iv: ''}.tap {|i|
|
|
27
|
+
i.define_singleton_method(:to_s){''}
|
|
28
|
+
i.define_singleton_method(:blank?){true}
|
|
29
|
+
i.define_singleton_method(:empty?){true}
|
|
30
|
+
i.define_singleton_method(:presence){''}
|
|
31
|
+
i.define_singleton_method(:present?){false}
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def decrypt(options = {})
|
|
37
|
+
if options.is_a? String
|
|
38
|
+
text = options.dup
|
|
39
|
+
options = {}
|
|
40
|
+
if text.scan(/:/).one?
|
|
41
|
+
options[:encrypted], options[:iv] = text.split(':')
|
|
42
|
+
else
|
|
43
|
+
raise 'Invalid String input!'
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
raise ':encrypted required!' unless options.has_key?(:encrypted)
|
|
47
|
+
raise ':iv required!' unless options.has_key?(:iv)
|
|
48
|
+
raise ':encrypted invalid type!' unless options[:encrypted].is_a? String
|
|
49
|
+
raise ':iv invalid type!' unless options[:iv].is_a? String
|
|
50
|
+
return '' if options[:encrypted].strip.empty? and options[:iv].strip.empty?
|
|
51
|
+
@cipher.decrypt
|
|
52
|
+
@cipher.key = key(options) || @key
|
|
53
|
+
@cipher.iv = Base64.decode64(options[:iv].encode('ascii-8bit'))
|
|
54
|
+
decrypted = @cipher.update Base64.decode64(options[:encrypted].encode('ascii-8bit'))
|
|
55
|
+
begin
|
|
56
|
+
decrypted << @cipher.final
|
|
57
|
+
Marshal.load(decrypted)
|
|
58
|
+
rescue
|
|
59
|
+
raise 'Decryption failed.'
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def key(options = {})
|
|
64
|
+
return nil unless options.has_key? :key
|
|
65
|
+
options.has_key?(:salt) ? Armor.digest(options[:key], options[:salt]) : options[:key]
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module AESKeeper
|
|
2
|
+
class AESKeeperPure
|
|
3
|
+
def initialize(options = {})
|
|
4
|
+
raise ":key required!" unless options.has_key? :key
|
|
5
|
+
raise ":key needs to be at-least 32 characters!" unless options[:key].length >= 32
|
|
6
|
+
@key = key(options)
|
|
7
|
+
@cipher = OpenSSL::Cipher::AES256.new(:CBC)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def encrypt(content, options = {})
|
|
11
|
+
if (content != nil) and (content != "")
|
|
12
|
+
@cipher.encrypt
|
|
13
|
+
@cipher.key = key(options) || @key
|
|
14
|
+
@iv ||= @cipher.random_iv
|
|
15
|
+
@cipher.iv = @iv
|
|
16
|
+
encrypted = @cipher.update content
|
|
17
|
+
encrypted << @cipher.final
|
|
18
|
+
{
|
|
19
|
+
encrypted: Base64.encode64(encrypted).encode('utf-8'), iv: Base64.encode64(@iv).encode('utf-8')
|
|
20
|
+
}.tap { |i|
|
|
21
|
+
i.define_singleton_method(:to_s) { [self[:encrypted], self[:iv]].join(":") }
|
|
22
|
+
i.define_singleton_method(:to_string) { [self[:encrypted], self[:iv]].join(":") }
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
{ encrypted: '', iv: ''}.tap {|i|
|
|
26
|
+
i.define_singleton_method(:to_s){''}
|
|
27
|
+
i.define_singleton_method(:blank?){true}
|
|
28
|
+
i.define_singleton_method(:empty?){true}
|
|
29
|
+
i.define_singleton_method(:presence){''}
|
|
30
|
+
i.define_singleton_method(:present?){false}
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def decrypt(options = {})
|
|
36
|
+
if options.is_a? String
|
|
37
|
+
text = options.dup
|
|
38
|
+
options = {}
|
|
39
|
+
if text.scan(/:/).one?
|
|
40
|
+
options[:encrypted], options[:iv] = text.split(':')
|
|
41
|
+
else
|
|
42
|
+
raise 'Invalid String input!'
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
raise ':encrypted required!' unless options.has_key?(:encrypted)
|
|
46
|
+
raise ':iv required!' unless options.has_key?(:iv)
|
|
47
|
+
raise ':encrypted invalid type!' unless options[:encrypted].is_a? String
|
|
48
|
+
raise ':iv invalid type!' unless options[:iv].is_a? String
|
|
49
|
+
return '' if options[:encrypted].strip.empty? and options[:iv].strip.empty?
|
|
50
|
+
@cipher.decrypt
|
|
51
|
+
@cipher.key = key(options) || @key
|
|
52
|
+
@cipher.iv = Base64.decode64(options[:iv].encode('ascii-8bit'))
|
|
53
|
+
decrypted = @cipher.update Base64.decode64(options[:encrypted].encode('ascii-8bit'))
|
|
54
|
+
begin
|
|
55
|
+
decrypted << @cipher.final
|
|
56
|
+
decrypted
|
|
57
|
+
rescue
|
|
58
|
+
raise 'Decryption failed.'
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def key(options = {})
|
|
63
|
+
return nil unless options.has_key? :key
|
|
64
|
+
options.has_key?(:salt) ? Armor.digest(options[:key], options[:salt]) : options[:key]
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
data/lib/aes_keeper/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
VERSION = "0.0
|
|
1
|
+
module AESKeeper
|
|
2
|
+
VERSION = "0.1.0"
|
|
3
3
|
end
|
data/lib/aes_keeper.rb
CHANGED
|
@@ -1,69 +1,9 @@
|
|
|
1
1
|
require "aes_keeper/version"
|
|
2
2
|
require 'armor'
|
|
3
3
|
require 'base64'
|
|
4
|
+
require 'aes_keeper/aes_keeper_pure.rb'
|
|
5
|
+
require 'aes_keeper/aes_keeper_marshal.rb'
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
raise ":key needs to be at-least 32 characters!" unless options[:key].length >= 32
|
|
9
|
-
@key = key(options)
|
|
10
|
-
@cipher = OpenSSL::Cipher::AES256.new(:CBC)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def encrypt(content, options = {})
|
|
14
|
-
if (content != nil) and (content != "")
|
|
15
|
-
@cipher.encrypt
|
|
16
|
-
@cipher.key = key(options) || @key
|
|
17
|
-
iv = @cipher.random_iv
|
|
18
|
-
@cipher.iv = iv
|
|
19
|
-
encrypted = @cipher.update Marshal.dump(content)
|
|
20
|
-
encrypted << @cipher.final
|
|
21
|
-
{
|
|
22
|
-
encrypted: Base64.encode64(encrypted).encode('utf-8'), iv: Base64.encode64(iv).encode('utf-8')
|
|
23
|
-
}.tap { |i|
|
|
24
|
-
i.define_singleton_method(:to_s) { [self[:encrypted], self[:iv]].join(":") }
|
|
25
|
-
i.define_singleton_method(:to_string) { [self[:encrypted], self[:iv]].join(":") }
|
|
26
|
-
}
|
|
27
|
-
else
|
|
28
|
-
{ encrypted: '', iv: ''}.tap {|i|
|
|
29
|
-
i.define_singleton_method(:to_s){''}
|
|
30
|
-
i.define_singleton_method(:blank?){true}
|
|
31
|
-
i.define_singleton_method(:empty?){true}
|
|
32
|
-
i.define_singleton_method(:presence){''}
|
|
33
|
-
i.define_singleton_method(:present?){false}
|
|
34
|
-
}
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def decrypt(options = {})
|
|
39
|
-
if options.is_a? String
|
|
40
|
-
text = options.dup
|
|
41
|
-
options = {}
|
|
42
|
-
if text.scan(/:/).one?
|
|
43
|
-
options[:encrypted], options[:iv] = text.split(':')
|
|
44
|
-
else
|
|
45
|
-
raise 'Invalid String input!'
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
raise ':encrypted required!' unless options.has_key?(:encrypted)
|
|
49
|
-
raise ':iv required!' unless options.has_key?(:iv)
|
|
50
|
-
raise ':encrypted invalid type!' unless options[:encrypted].is_a? String
|
|
51
|
-
raise ':iv invalid type!' unless options[:iv].is_a? String
|
|
52
|
-
return '' if options[:encrypted].strip.empty? and options[:iv].strip.empty?
|
|
53
|
-
@cipher.decrypt
|
|
54
|
-
@cipher.key = key(options) || @key
|
|
55
|
-
@cipher.iv = Base64.decode64(options[:iv].encode('ascii-8bit'))
|
|
56
|
-
decrypted = @cipher.update Base64.decode64(options[:encrypted].encode('ascii-8bit'))
|
|
57
|
-
begin
|
|
58
|
-
decrypted << @cipher.final
|
|
59
|
-
Marshal.load(decrypted)
|
|
60
|
-
rescue
|
|
61
|
-
raise 'Decryption failed.'
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def key(options = {})
|
|
66
|
-
return nil unless options.has_key? :key
|
|
67
|
-
options.has_key?(:salt) ? Armor.digest(options[:key], options[:salt]) : options[:key]
|
|
68
|
-
end
|
|
69
|
-
end
|
|
7
|
+
module AESKeeper
|
|
8
|
+
::AesKeeper = AESKeeperMarshal
|
|
9
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'minitest_helper'
|
|
2
|
+
|
|
3
|
+
describe AESKeeper::AESKeeperMarshal do
|
|
4
|
+
let(:uuid) { SecureRandom.uuid }
|
|
5
|
+
let(:encrypt1){AesKeeper.new key: "asdfghjklqwertyuiopzxcvbnm1234567890"}
|
|
6
|
+
let(:encrypt2){AesKeeper.new key: "asdfghjklqwertyuiopzxcvbnm1234567890", salt: "shaker"}
|
|
7
|
+
let(:encrypt3){AesKeeper.new key: uuid, salt: "Example.com"}
|
|
8
|
+
|
|
9
|
+
it "shows version for old implementation" do
|
|
10
|
+
_(AesKeeper::VERSION.class).must_be_same_as String
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "produces a hash of size 2" do
|
|
14
|
+
hsh = encrypt1.encrypt("moo")
|
|
15
|
+
_(hsh).must_be_kind_of Hash
|
|
16
|
+
_(hsh.size).must_be_same_as 2
|
|
17
|
+
_(hsh).must_include :iv
|
|
18
|
+
_(hsh).must_include :encrypted
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "can be as a string as well" do
|
|
22
|
+
str = encrypt2.encrypt("moo").to_s
|
|
23
|
+
_(str).must_be_kind_of String
|
|
24
|
+
_(str.count(":")).must_be_same_as 1
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "encrypts and decrypts #1" do
|
|
28
|
+
a = encrypt1.encrypt("moo")
|
|
29
|
+
_(encrypt1.decrypt(a)).must_equal "moo"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "encrypts and decrypts #2" do
|
|
33
|
+
b = encrypt2.encrypt("moo")
|
|
34
|
+
_(encrypt2.decrypt(b)).must_equal "moo"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "encrypts and decrypts #3" do
|
|
38
|
+
c = encrypt1.encrypt("moo").to_s
|
|
39
|
+
_(encrypt1.decrypt(c)).must_equal "moo"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "encrypts and decrypts #4" do
|
|
43
|
+
d = encrypt2.encrypt("moo").to_s
|
|
44
|
+
_(encrypt2.decrypt(d)).must_equal "moo"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "encrypts and decrypts #5" do
|
|
48
|
+
e = encrypt3.encrypt(uuid).to_s
|
|
49
|
+
_(encrypt3.decrypt(e)).must_equal uuid
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'minitest_helper'
|
|
2
|
+
|
|
3
|
+
describe AESKeeper::AESKeeperPure do
|
|
4
|
+
let(:uuid) { SecureRandom.uuid }
|
|
5
|
+
let(:encrypt1){AESKeeper::AESKeeperPure.new key: "asdfghjklqwertyuiopzxcvbnm1234567890"}
|
|
6
|
+
let(:encrypt2){AESKeeper::AESKeeperPure.new key: "asdfghjklqwertyuiopzxcvbnm1234567890", salt: "shaker"}
|
|
7
|
+
let(:encrypt3){AESKeeper::AESKeeperPure.new key: uuid, salt: "Example.com"}
|
|
8
|
+
|
|
9
|
+
it "produces a hash of size 2" do
|
|
10
|
+
hsh = encrypt1.encrypt("moo")
|
|
11
|
+
_(hsh).must_be_kind_of Hash
|
|
12
|
+
_(hsh.size).must_be_same_as 2
|
|
13
|
+
_(hsh).must_include :iv
|
|
14
|
+
_(hsh).must_include :encrypted
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "pure aes results with injected iv will be consistent" do
|
|
18
|
+
encrypt2.instance_exec {@iv = "\xF6s\x93<\xCB\x8DX\x88\x84\xB9J\x04\x93l^\x8F"}
|
|
19
|
+
a = encrypt2.encrypt("asdf@moo.com").to_s
|
|
20
|
+
b = encrypt2.encrypt("asdf@moo.com").to_s
|
|
21
|
+
_(a).must_equal b
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "can be as a string as well" do
|
|
25
|
+
str = encrypt2.encrypt("moo").to_s
|
|
26
|
+
_(str).must_be_kind_of String
|
|
27
|
+
_(str.count(":")).must_be_same_as 1
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "encrypts and decrypts #1" do
|
|
31
|
+
a = encrypt1.encrypt("moo")
|
|
32
|
+
_(encrypt1.decrypt(a)).must_equal "moo"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "encrypts and decrypts #2" do
|
|
36
|
+
b = encrypt2.encrypt("moo")
|
|
37
|
+
_(encrypt2.decrypt(b)).must_equal "moo"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "encrypts and decrypts #3" do
|
|
41
|
+
c = encrypt1.encrypt("moo").to_s
|
|
42
|
+
_(encrypt1.decrypt(c)).must_equal "moo"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "encrypts and decrypts #4" do
|
|
46
|
+
d = encrypt2.encrypt("moo").to_s
|
|
47
|
+
_(encrypt2.decrypt(d)).must_equal "moo"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "encrypts and decrypts #5" do
|
|
51
|
+
e = encrypt3.encrypt(uuid).to_s
|
|
52
|
+
_(encrypt3.decrypt(e)).must_equal uuid
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require 'aes_keeper'
|
|
3
|
+
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
require 'color_pound_spec_reporter'
|
|
6
|
+
|
|
7
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
8
|
+
|
|
9
|
+
Minitest::Reporters.use! [ColorPoundSpecReporter.new]
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aes_keeper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel P. Clark
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -30,14 +30,56 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '10.
|
|
33
|
+
version: '10.5'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '10.
|
|
40
|
+
version: '10.5'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.8'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.8'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: minitest-reporters
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 1.1.7
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 1.1.7
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: color_pound_spec_reporter
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 0.0.5
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 0.0.5
|
|
41
83
|
- !ruby/object:Gem::Dependency
|
|
42
84
|
name: armor
|
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,7 +108,12 @@ files:
|
|
|
66
108
|
- Rakefile
|
|
67
109
|
- aes_keeper.gemspec
|
|
68
110
|
- lib/aes_keeper.rb
|
|
111
|
+
- lib/aes_keeper/aes_keeper_marshal.rb
|
|
112
|
+
- lib/aes_keeper/aes_keeper_pure.rb
|
|
69
113
|
- lib/aes_keeper/version.rb
|
|
114
|
+
- test/aes_keeper_marshal_test.rb
|
|
115
|
+
- test/aes_keeper_pure_test.rb
|
|
116
|
+
- test/minitest_helper.rb
|
|
70
117
|
homepage: https://github.com/danielpclark/aes_keeper
|
|
71
118
|
licenses:
|
|
72
119
|
- MIT
|
|
@@ -87,8 +134,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
134
|
version: '0'
|
|
88
135
|
requirements: []
|
|
89
136
|
rubyforge_project:
|
|
90
|
-
rubygems_version: 2.
|
|
137
|
+
rubygems_version: 2.5.1
|
|
91
138
|
signing_key:
|
|
92
139
|
specification_version: 4
|
|
93
140
|
summary: Encrypt data via AES to database worthy strings.
|
|
94
|
-
test_files:
|
|
141
|
+
test_files:
|
|
142
|
+
- test/aes_keeper_marshal_test.rb
|
|
143
|
+
- test/aes_keeper_pure_test.rb
|
|
144
|
+
- test/minitest_helper.rb
|