crypt_keeper 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bebe9201328a264bc331e557bfb7b29eda6f8cec
4
- data.tar.gz: f429009d3af1a7a09e8a3a4e45f21211994491c8
3
+ metadata.gz: ad20b829cfe76208db3c0bc6cf992a278bbd9659
4
+ data.tar.gz: 15c42c4227ed3505c4eb0af0c511d81b258ba937
5
5
  SHA512:
6
- metadata.gz: 16879b1ba1a690e850e5f1a26fb0d3f9db237b926acaf1dfdfab4d490da7723e2a7d079223d626a293916661ed1c63c29673a71a2d318482e99ecceb02b8c379
7
- data.tar.gz: 52a28a7ba7a2a3ed75fc9194bc5d42cb1fff57249aab11681c0288b90f3babbe6e4340c05320ea07cbe62402fe252454c33b36361ed09a3758eb32ede731e680
6
+ metadata.gz: df0c80648cd1bf39b88b81b5fd2e5b6fb404d01bbf529452453ab1bbd4c1654b578f274fc35a82f36d66014c62804c88363c2762af6383127e8ecc437c8b02ff
7
+ data.tar.gz: aa457783481ed45731f0d1191907044a4904ec702365c6b9325e7219678329c86632ccf20e16cc2f9e7ff9008218741114d2a3fe0f8de57eea72baaf0c6baf64
data/README.md CHANGED
@@ -47,6 +47,35 @@ expected behavior, and has its use cases. An example would be migrating from
47
47
  one type of encryption to another. Using `update_column` would allow you to
48
48
  update the content without going through the current encryptor.
49
49
 
50
+ ## Encodings
51
+
52
+ You can force an encoding on the plaintext before encryption and after decryption by using the `encoding` option. This is useful when dealing with multibyte strings:
53
+
54
+ ```ruby
55
+ class MyModel < ActiveRecord::Base
56
+ crypt_keeper :field, :other_field, :encryptor => :aes_new, :key => 'super_good_password', salt: 'salt', :encoding => 'UTF-8'
57
+ end
58
+
59
+ model = MyModel.new(field: 'Tromsø')
60
+ model.save! #=> Your data is now encrypted
61
+ model.field #=> 'Tromsø'
62
+ model.field.encoding #=> #<Encoding:UTF-8>
63
+ ```
64
+
65
+ ## Adding encryption to an existing table
66
+
67
+ If you are working with an existing table you would like to encrypt, you must use the `MyExistingModel.encrypt_table!` class method.
68
+
69
+ ```ruby
70
+ class MyExistingModel < ActiveRecord::Base
71
+ crypt_keeper :field, :other_field, :encryptor => :aes_new, :key => 'super_good_password', salt: 'salt'
72
+ end
73
+
74
+ MyExistingModel.encrypt_table!
75
+ ```
76
+
77
+ Running `encrypt_table!` will encrypt all rows in the database using the encryption method specificed by the `crypt_keeper` line in your model.
78
+
50
79
  ## Supported Available Encryptors
51
80
 
52
81
  There are four supported encryptors: `aes_new`, `mysql_aes_new`, `postgresql_pgp`, `postgres_pgp_public_key`.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/justin/work/jmazzi/crypt_keeper
3
3
  specs:
4
- crypt_keeper (0.16.0.pre)
4
+ crypt_keeper (0.17.0)
5
5
  activerecord (>= 3.1, < 4.2)
6
6
  activesupport (>= 3.1, < 4.2)
7
7
  aes (~> 0.5.0)
@@ -26,7 +26,7 @@ GEM
26
26
  bundler
27
27
  rake
28
28
  arel (2.2.3)
29
- armor (0.0.2)
29
+ armor (0.0.3)
30
30
  builder (3.0.4)
31
31
  coderay (1.0.9)
32
32
  coveralls (0.7.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/justin/work/jmazzi/crypt_keeper
3
3
  specs:
4
- crypt_keeper (0.16.0.pre)
4
+ crypt_keeper (0.17.0)
5
5
  activerecord (>= 3.1, < 4.2)
6
6
  activesupport (>= 3.1, < 4.2)
7
7
  aes (~> 0.5.0)
@@ -26,7 +26,7 @@ GEM
26
26
  bundler
27
27
  rake
28
28
  arel (3.0.2)
29
- armor (0.0.2)
29
+ armor (0.0.3)
30
30
  builder (3.0.4)
31
31
  coderay (1.0.9)
32
32
  coveralls (0.7.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/justin/work/jmazzi/crypt_keeper
3
3
  specs:
4
- crypt_keeper (0.16.0.pre)
4
+ crypt_keeper (0.17.0)
5
5
  activerecord (>= 3.1, < 4.2)
6
6
  activesupport (>= 3.1, < 4.2)
7
7
  aes (~> 0.5.0)
@@ -30,7 +30,7 @@ GEM
30
30
  bundler
31
31
  rake
32
32
  arel (4.0.0)
33
- armor (0.0.2)
33
+ armor (0.0.3)
34
34
  atomic (1.1.14)
35
35
  builder (3.1.4)
36
36
  coderay (1.0.9)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/justin/work/jmazzi/crypt_keeper
3
3
  specs:
4
- crypt_keeper (0.16.0.pre)
4
+ crypt_keeper (0.17.0)
5
5
  activerecord (>= 3.1, < 4.2)
6
6
  activesupport (>= 3.1, < 4.2)
7
7
  aes (~> 0.5.0)
@@ -80,6 +80,22 @@ module CryptKeeper
80
80
  end
81
81
  end
82
82
 
83
+ # Public: Encrypt a table for the first time.
84
+ def encrypt_table!
85
+ enc = encryptor_klass.new(crypt_keeper_options)
86
+ tmp_table = Class.new(ActiveRecord::Base).tap { |c| c.table_name = self.table_name }
87
+
88
+ transaction do
89
+ tmp_table.find_each do |r|
90
+ crypt_keeper_fields.each do |field|
91
+ r.send("#{field}=", enc.encrypt(r[field])) if r[field].present?
92
+ end
93
+
94
+ r.save!
95
+ end
96
+ end
97
+ end
98
+
83
99
  private
84
100
 
85
101
  # Private: The encryptor class
@@ -1,3 +1,3 @@
1
1
  module CryptKeeper
2
- VERSION = "0.17.0"
2
+ VERSION = "0.18.0"
3
3
  end
data/spec/model_spec.rb CHANGED
@@ -112,5 +112,20 @@ module CryptKeeper
112
112
  expect(record.storage.encoding.name).to eql('UTF-8')
113
113
  end
114
114
  end
115
+
116
+ context "Initial Table Encryption" do
117
+ before do
118
+ SensitiveData.crypt_keeper :storage, key: 'tool', salt: 'salt', encryptor: :aes_new, encoding: 'utf-8'
119
+ SensitiveData.delete_all
120
+ c = Class.new(ActiveRecord::Base).tap {|c| c.table_name = 'sensitive_data' }
121
+ 5.times { |i| c.create! storage: "testing#{i}" }
122
+ end
123
+
124
+ it "encrypts the table" do
125
+ expect { SensitiveData.first(5) }.to raise_error(OpenSSL::Cipher::CipherError)
126
+ SensitiveData.encrypt_table!
127
+ expect { SensitiveData.first(5) }.not_to raise_error
128
+ end
129
+ end
115
130
  end
116
131
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypt_keeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Mazzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-01 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord