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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b19235367f67525fa9762a3d8ac24412940681b
4
- data.tar.gz: c81a93aea5d4df6915691473be8cb0234bed2cb2
3
+ metadata.gz: 2ec8280c8a6ae60580cd5283a0156bbced5d56b7
4
+ data.tar.gz: e774ff6e6838bff3bd49e228aeb14adc21f594ea
5
5
  SHA512:
6
- metadata.gz: 18c67e2f85158fab8883c90191a0dd01e8ba9052906c66dc45e49c41e521e1877088de91b6da607f747893141bce8938c152a516394d8774d20319f0e8cf882f
7
- data.tar.gz: 1d58c450b06c03e55a9ab06d9423f9fd0bce76a0ccf43593f4f1ce9915e3513a275dbe737301ada17c06af83f7a3d670b5c9f26094076fc284e0719fbeaecb5f
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 as the 32 bytes preceding the encrypted data.
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
- #=> "\x13\xC4\x18\xE4\x1E.^HU0\rOZs\xFE7@\xC0\xB3\xB6\x9F\"\xE6M\xA6\xF4\xC4a\x85\x89\xECtW\xF9\x9DN\xA1_6\x8Bd\x0F\x19b"
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. :cake:
39
+ 4. :pineapple:
@@ -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
- salt << iv << cipher.update(self) << cipher.final
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
- return nil unless self.bytesize > 32
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 = self.byteslice(16..31)
21
- cipher.update(self.byteslice(32..-1)) << cipher.final
19
+ cipher.iv = iv
20
+ cipher.update(encrypted) << cipher.final
22
21
  end
23
22
  end
24
23
  end
@@ -1,3 +1,3 @@
1
1
  module Encrypt
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -10,7 +10,11 @@ describe Encrypt do
10
10
  end
11
11
 
12
12
  it 'encrypts' do
13
- @encrypted.bytes.count == 38
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.5
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-12 00:00:00.000000000 Z
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.4
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