encrypt 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/encrypt.rb +5 -6
- data/lib/encrypt/version.rb +1 -1
- data/test/encrypt_test.rb +5 -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: 2ec8280c8a6ae60580cd5283a0156bbced5d56b7
|
4
|
+
data.tar.gz: e774ff6e6838bff3bd49e228aeb14adc21f594ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f08646430895d8ce7f4f7a3690c456b83f3e3f2ee49155d7a1922713a12d71bfddd7aebcb8b945946be8da2dbc2d4981f52bdd3041d91f7bbdc3147a9cdea382
|
7
|
+
data.tar.gz: 30a5dee8f3f1239ce0bf604604c1849dfd0fe0a5fbb8712cc8047dbc48482c9902c47a54ebcdb03dc2045ba26e10797dfeb36bd4fa2bbffa74be58ed5aaec842
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A gem for encrypting and decrypting strings with AES-256. Just supply the password.
|
4
4
|
|
5
|
-
Encrypt uses an AES-256 cipher in CTR mode. A randomly generated salt and IV are publicly stored
|
5
|
+
Encrypt uses an AES-256 cipher in CTR mode. A randomly generated salt and IV are publicly stored along with the encrypted data.
|
6
6
|
|
7
7
|
Encrypt makes use of Ruby 2.0's experimental refinements to extend String locally, adding the #encrypt and #decrypt methods. Activate the refinement with using: `using Encrypt`.
|
8
8
|
|
@@ -14,7 +14,7 @@ require 'encrypt'
|
|
14
14
|
using Encrypt
|
15
15
|
|
16
16
|
encrypted = 'super sekret'.encrypt 'passw0rd'
|
17
|
-
#=> "\
|
17
|
+
#=> "\x04\b[\b\"\x15H\xEB\x8C\xE6\xA2r\xDA\x15\xDDH\xEB\xF2|\x11\xEFF\"\x15\xE9\xBB\xB1\xCEO\xB6Y\x19zk\xDD\xD5\x9A\xBD\x01\xF5\"\x11F/1\x1D;2g\xFC\xB8np\xBC"
|
18
18
|
|
19
19
|
encrypted.decrypt 'passw0rd'
|
20
20
|
#=> "super sekret"
|
@@ -28,9 +28,12 @@ encrypted.decrypt 'passw0rd'
|
|
28
28
|
|
29
29
|
Ruby 2.0.0+ (uses [experimental refinements](http://www.ruby-doc.org/core-2.0/doc/syntax/refinements_rdoc.html))
|
30
30
|
|
31
|
+
## Alternatives
|
32
|
+
The [RbNACL](https://github.com/cryptosphere/rbnacl#readme) gem has been more thoroughly vetted and is a recommended alternative.
|
33
|
+
|
31
34
|
## Contributing
|
32
35
|
|
33
36
|
1. Fork it
|
34
37
|
2. Commit changes
|
35
38
|
3. Submit a Pull Request
|
36
|
-
4. :
|
39
|
+
4. :pineapple:
|
data/lib/encrypt.rb
CHANGED
@@ -5,20 +5,19 @@ module Encrypt
|
|
5
5
|
def encrypt key
|
6
6
|
cipher = OpenSSL::Cipher::AES256.new(:CTR)
|
7
7
|
cipher.encrypt
|
8
|
-
iv = cipher.random_iv
|
9
8
|
salt = OpenSSL::Random.random_bytes(16)
|
10
9
|
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
|
11
|
-
|
10
|
+
iv = cipher.random_iv
|
11
|
+
Marshal.dump([salt, iv, cipher.update(self) << cipher.final])
|
12
12
|
end
|
13
13
|
|
14
14
|
def decrypt key
|
15
|
-
|
15
|
+
salt, iv, encrypted = Marshal.load(self)
|
16
16
|
cipher = OpenSSL::Cipher::AES256.new(:CTR)
|
17
17
|
cipher.decrypt
|
18
|
-
salt = self.byteslice(0..15)
|
19
18
|
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
|
20
|
-
cipher.iv =
|
21
|
-
cipher.update(
|
19
|
+
cipher.iv = iv
|
20
|
+
cipher.update(encrypted) << cipher.final
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
data/lib/encrypt/version.rb
CHANGED
data/test/encrypt_test.rb
CHANGED
@@ -10,7 +10,11 @@ describe Encrypt do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'encrypts' do
|
13
|
-
@encrypted
|
13
|
+
assert @encrypted != 'sekret'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'does not decrypt with incorrect key' do
|
17
|
+
refute_equal 'sekret', @encrypted.decrypt('password')
|
14
18
|
end
|
15
19
|
|
16
20
|
it 'decrypts' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encrypt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shannon Skipper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
77
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.0.
|
78
|
+
rubygems_version: 2.0.5
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: 'Encrypt and decrypt strings with AES-256 in CTR mode. Encrypt uses Ruby
|