encrypt 0.0.7 → 0.1.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: 0d684965f08f27df16f79603de53e051a1e298ef
4
- data.tar.gz: 1812dea161842d1dba9054ca37ad70aad4fc5908
3
+ metadata.gz: b5a2c539cd1c3ff0f89535d23b33a8a906dabc58
4
+ data.tar.gz: c4efa4ff9b249343eb7a340c62917404b635cbd7
5
5
  SHA512:
6
- metadata.gz: 365b36944af7fbde9e44aec92f5ea14785ecbde4d33c550bae78512a3196ff0c53bb3cb2bd0ba41e1bb7db0ac8d2b34c4db98a55698e0ef7855d9a7477163e84
7
- data.tar.gz: 45a6893dc869fe0ef1f0980ff220fee735539c336e9534fab705f250c16715ea0faaedf434a84e16dc7327ab8a3dc0196b4e67b005ac54903b4fd283dcf671d0
6
+ metadata.gz: 7ffe6339efb5999f725a23fd67052b28c24454a4779d93a3653c768b528e4e8bbfc4f049026d6d2db4e357c2e49891ee4acbc325c66b497b94552ecd5ead52c6
7
+ data.tar.gz: 42dfdacbdba317defe3fa553504b9fa620b606a12d252bd74dca2a354f2e325789bb4ff222f5533bb8a7eb5dacaa0bbbf7a88be84b53e2c3eac3c92e85ef657a
data/README.md CHANGED
@@ -1,38 +1,28 @@
1
1
  # Encrypt
2
2
 
3
- A gem for encrypting and decrypting strings with AES-256. Just supply the password.
3
+ A gem for encrypting and decrypting strings with AES-256. Just supply a String and the password.
4
4
 
5
5
  Encrypt uses an AES-256 cipher in CBC mode. A randomly generated salt and IV are publicly stored along with the encrypted data.
6
6
 
7
- Encrypt makes use of refinements to extend String locally, adding the #encrypt and #decrypt methods. Activate the refinement with `using Encrypt`.
8
-
9
7
  ## Usage
10
8
 
11
9
  ```ruby
12
10
  require 'encrypt'
13
11
 
14
- 'not yet'.encrypt 'refinement not activated'
15
- #=> NoMethodError: undefined method `encrypt' for "not yet":String
16
-
17
- using Encrypt
12
+ encrypted = Encrypt.dump 'super sekret message', 'passw0rd'
13
+ #=>
18
14
 
19
- encrypted = 'super sekret'.encrypt 'passw0rd'
20
- #=> "\x04\b[\b\"\x15\x9FK\x18+\xA3X\x96S\xD9\xF2L. \x15\a2\"\x15,x)\xE2\xDA~\xA0\x90M\x06\xB0\xAC&\x89\xEFw\"\x15n\x90\xDCq2\x9B\xA8\x80Ca\xBB\x0F+NT\xD4"
15
+ Encrypt.load encrypted, 'passw0rd'
16
+ #=> "super sekret message"
21
17
 
22
- encrypted.decrypt 'passw0rd'
23
- #=> "super sekret"
24
-
25
- encrypted.decrypt 'wrong'
18
+ Encrypt.load encrypted, 'wrong'
26
19
  #=> OpenSSL::Cipher::CipherError: bad decrypt
27
20
  ```
28
21
 
29
22
  ## Installation
30
-
31
- $ gem install encrypt
32
-
33
- ## Requirements
34
-
35
- Ruby 2.0.0+ (uses [experimental refinements](http://www.ruby-doc.org/core-2.0/doc/syntax/refinements_rdoc.html))
23
+ ```ruby
24
+ gem install encrypt
25
+ ```
36
26
 
37
27
  ## Alternatives
38
28
 
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.version = Encrypt::VERSION
7
7
  spec.authors = ['Shannon Skipper']
8
8
  spec.email = ['shannonskipper@gmail.com']
9
- spec.description = %q{A gem for encrypting and decrypting strings with AES-256. Just supply the password.}
10
- spec.summary = %q{Encrypt and decrypt strings with AES-256 in CBC mode. Encrypt uses Ruby refinements to extend String locally to add the #encrypt and #decrypt methods.}
9
+ spec.description = %q{Encrypt and decrypt strings with AES-256. Just supply the password.}
10
+ spec.summary = %q{Encrypt and decrypt strings with AES-256 in CBC mode.}
11
11
  spec.homepage = 'https://github.com/havenwood/encrypt#readme'
12
12
  spec.license = 'MIT'
13
13
  spec.files = `git ls-files`.split($/)
@@ -1,23 +1,21 @@
1
1
  require 'openssl'
2
2
 
3
3
  module Encrypt
4
- refine String do
5
- def encrypt key
6
- cipher = OpenSSL::Cipher::AES256.new(:CBC)
7
- cipher.encrypt
8
- salt = OpenSSL::Random.random_bytes(16)
9
- cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
10
- iv = cipher.random_iv
11
- Marshal.dump([salt, iv, cipher.update(self) << cipher.final])
12
- end
4
+ def self.dump string, key
5
+ cipher = OpenSSL::Cipher::AES256.new(:CBC)
6
+ cipher.encrypt
7
+ salt = OpenSSL::Random.random_bytes(16)
8
+ cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
9
+ iv = cipher.random_iv
10
+ Marshal.dump([salt, iv, cipher.update(string) << cipher.final])
11
+ end
13
12
 
14
- def decrypt key
15
- salt, iv, encrypted = Marshal.load(self)
16
- cipher = OpenSSL::Cipher::AES256.new(:CBC)
17
- cipher.decrypt
18
- cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
19
- cipher.iv = iv
20
- cipher.update(encrypted) << cipher.final
21
- end
13
+ def self.load string, key
14
+ salt, iv, encrypted = Marshal.load(string)
15
+ cipher = OpenSSL::Cipher::AES256.new(:CBC)
16
+ cipher.decrypt
17
+ cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
18
+ cipher.iv = iv
19
+ cipher.update(encrypted) << cipher.final
22
20
  end
23
21
  end
@@ -1,3 +1,3 @@
1
1
  module Encrypt
2
- VERSION = '0.0.7'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -6,7 +6,7 @@ using Encrypt
6
6
 
7
7
  describe Encrypt do
8
8
  before do
9
- @encrypted = 'sekret'.encrypt('passw0rd')
9
+ @encrypted = Encrypt.dump 'sekret', 'passw0rd'
10
10
  end
11
11
 
12
12
  it 'encrypts' do
@@ -14,10 +14,12 @@ describe Encrypt do
14
14
  end
15
15
 
16
16
  it 'does not decrypt with incorrect key' do
17
- assert_raises(OpenSSL::Cipher::CipherError) { @encrypted.decrypt('pwd') }
17
+ assert_raises(OpenSSL::Cipher::CipherError) do
18
+ Encrypt.load @encrypted, 'wrong pwd'
19
+ end
18
20
  end
19
21
 
20
22
  it 'decrypts' do
21
- assert_equal 'sekret', @encrypted.decrypt('passw0rd')
23
+ assert_equal 'sekret', Encrypt.load(@encrypted, 'passw0rd')
22
24
  end
23
25
  end
metadata CHANGED
@@ -1,52 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encrypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
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-22 00:00:00.000000000 Z
11
+ date: 2014-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
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
40
  version: '0'
41
- description: A gem for encrypting and decrypting strings with AES-256. Just supply
42
- the password.
41
+ description: Encrypt and decrypt strings with AES-256. Just supply the password.
43
42
  email:
44
43
  - shannonskipper@gmail.com
45
44
  executables: []
46
45
  extensions: []
47
46
  extra_rdoc_files: []
48
47
  files:
49
- - .gitignore
48
+ - ".gitignore"
50
49
  - Gemfile
51
50
  - LICENSE.txt
52
51
  - README.md
@@ -65,21 +64,20 @@ require_paths:
65
64
  - lib
66
65
  required_ruby_version: !ruby/object:Gem::Requirement
67
66
  requirements:
68
- - - '>='
67
+ - - ">="
69
68
  - !ruby/object:Gem::Version
70
69
  version: '0'
71
70
  required_rubygems_version: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - '>='
72
+ - - ">="
74
73
  - !ruby/object:Gem::Version
75
74
  version: '0'
76
75
  requirements: []
77
76
  rubyforge_project:
78
- rubygems_version: 2.0.5
77
+ rubygems_version: 2.2.0
79
78
  signing_key:
80
79
  specification_version: 4
81
- summary: 'Encrypt and decrypt strings with AES-256 in CBC mode. Encrypt uses Ruby
82
- refinements to extend String locally to add the #encrypt and #decrypt methods.'
80
+ summary: Encrypt and decrypt strings with AES-256 in CBC mode.
83
81
  test_files:
84
82
  - test/encrypt_test.rb
85
83
  has_rdoc: