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 +4 -4
- data/README.md +9 -19
- data/encrypt.gemspec +2 -2
- data/lib/encrypt.rb +15 -17
- data/lib/encrypt/version.rb +1 -1
- data/test/encrypt_test.rb +5 -3
- metadata +12 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5a2c539cd1c3ff0f89535d23b33a8a906dabc58
|
4
|
+
data.tar.gz: c4efa4ff9b249343eb7a340c62917404b635cbd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
15
|
-
#=>
|
16
|
-
|
17
|
-
using Encrypt
|
12
|
+
encrypted = Encrypt.dump 'super sekret message', 'passw0rd'
|
13
|
+
#=>
|
18
14
|
|
19
|
-
encrypted
|
20
|
-
#=> "
|
15
|
+
Encrypt.load encrypted, 'passw0rd'
|
16
|
+
#=> "super sekret message"
|
21
17
|
|
22
|
-
|
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
|
-
|
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
|
|
data/encrypt.gemspec
CHANGED
@@ -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{
|
10
|
-
spec.summary = %q{Encrypt and decrypt strings with AES-256 in CBC mode.
|
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($/)
|
data/lib/encrypt.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
|
3
3
|
module Encrypt
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
data/lib/encrypt/version.rb
CHANGED
data/test/encrypt_test.rb
CHANGED
@@ -6,7 +6,7 @@ using Encrypt
|
|
6
6
|
|
7
7
|
describe Encrypt do
|
8
8
|
before do
|
9
|
-
@encrypted = 'sekret'
|
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)
|
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
|
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
|
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:
|
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:
|
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
|
77
|
+
rubygems_version: 2.2.0
|
79
78
|
signing_key:
|
80
79
|
specification_version: 4
|
81
|
-
summary:
|
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:
|