encryption 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTBkNmY0MjNlNGVlZjI2NzNlOGM3NDBjM2UxYzlmYTJiMDI0MTcxYQ==
5
+ data.tar.gz: !binary |-
6
+ MGY0ZjExNjA3NGI2Yzk1ZGQ0NzM5YmQyZDM4ZmUxMDNjMmQwODYzMA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OWEyYWE2NzU0ZWQ2YmZkZmJhMmY4Yjc3ZGFlZWZiZTlhYTAxNDcwODQ5OTMx
10
+ Mjg1YjE5Njg2MmE2NWE0NmQ4NjExYWQ0MWQ0ZTY1ZTQ3NTM0ODZkNTZjOWVm
11
+ MmFmYzJhMGExOGYyMWJhMWFlODAzYzE5OWQ0ZDA3ZDExMDZkMjc=
12
+ data.tar.gz: !binary |-
13
+ ZDY1MjhkMTk1YWQ4YzQ1OTY3OTI5YTdiZmU5NTRmODE0MGVjZDQ3YWMyZTk5
14
+ ZjdhZjAxYzFhYThmN2I4Njc4ODliN2U3YzRmMGM5YTljYzk4Yzk3MDUyZDBi
15
+ NDY2ZGQ4ZmZmYzIwOGM2MGQ1MzBkOWNiNGNmMmY1N2E3YTEzOTk=
data/.travis.yml CHANGED
@@ -2,6 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 1.9.3
5
- - 1.9.2
6
- - jruby-19mode
7
- - rbx-19mode
5
+ - 1.9.2
data/README.md CHANGED
@@ -43,13 +43,13 @@ encryptor.decrypt(encrypted_str) == data # true
43
43
 
44
44
  Configuration
45
45
  -------------
46
- For symmetric encryption / decryption you need to set an encryption key. The rest of the settings are optional. Here is a list of all of them:
47
- `Encryption.key` - Your encryption key
48
- `Encryption.iv # Optional` - Encryption initialization vector. Defaults to the charecter `"\0"`
49
- `Encryption.cipher # Optional` - Your encryption algorithm. Defaults to `aes-256-cbc`
46
+ For symmetric encryption / decryption you need to set an encryption key. The rest of the settings are optional. Here is a list of all of them:
47
+ `Encryption.key` - Your encryption key
48
+ `Encryption.iv # Optional` - Encryption initialization vector. Defaults to the charecter `"\0"` _(Optional)_
49
+ `Encryption.cipher # Optional` - Your encryption algorithm. Defaults to `aes-256-cbc` _(Optional)_
50
50
  Run `openssl list-cipher-commands` in the terminal to list all installed ciphers or call `OpenSSL::Cipher.ciphers` in _Ruby_, which will return an array, containing all available algorithms.
51
51
 
52
- You can optionally configure both a global instance and a custom instance with a __block__:
52
+ You can optionally configure both a global instance and a custom instance with a _block_:
53
53
  ```ruby
54
54
  Encryption.config do |config|
55
55
  config.key = "don't look at me!"
@@ -98,15 +98,28 @@ public_key.encrypt("H3LL0¡")
98
98
  # Note that you can use both public and private keys to encrypt and decrypt data
99
99
  ```
100
100
 
101
- <!---
102
- Helpers
103
- -------
104
- String helpers
105
- --------------
106
101
 
107
- Array helpers
108
- -------------
102
+ Helpers
103
+ -------
104
+ String helper
105
+ -------------
106
+ The gem adds the `encrypt` and `decrypt` methods to the `String` class.
107
+ You can use them as follows:
108
+ ```ruby
109
+ # With the global Encryption instance
110
+ "Hello".encrypt
111
+ "Hello".encrypt!
112
+ "h3LL0".decrypt
113
+ "h3LL0".decrypt!
114
+
115
+ # With custom settings (and custom encryptor instance)
116
+ "Hello".encrypt({ key: 'encryption key', iv: 'initialization vector', cipher: 'encryption algorithm' })
117
+ ```
118
+
119
+ License
120
+ -------
121
+ This gem is distributed under the MIT License.
109
122
 
110
- Hash helpers
111
- ------------
112
- -->
123
+ Author
124
+ ------
125
+ Itay Grudev - ![Itay Grudev](http://safemail.justlikeed.net/e/a5307c0c2dd405f756cab9f4c76cd63a.png)
data/encryption.gemspec CHANGED
@@ -2,10 +2,10 @@ require 'date'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'encryption'
5
- s.version = '1.1.0'
5
+ s.version = '1.1.2'
6
6
  s.date = Date.today.to_s
7
7
  s.summary = 'A simple wrapper for the OpenSSL Cipher library'
8
- s.description = 'Encryption provides a simple interface for symmetric / asymmetric encryption and decryption with the OpenSSL Cipher library'
8
+ s.description = 'Encryption provides a simple interface for symmetric / asymmetric encryption with the OpenSSL Cipher library'
9
9
  s.authors = ['Itay Grudev']
10
10
  s.email = ['itay.grudev@gmail.com']
11
11
  s.homepage = 'https://github.com/Itehnological/encryption'
data/lib/encryption.rb CHANGED
@@ -2,6 +2,8 @@ require_relative 'configuration.rb'
2
2
  require_relative 'modules.rb'
3
3
  require_relative 'helpers.rb'
4
4
 
5
+ String.send(:include, Encryption::String)
6
+
5
7
  module Encryption
6
8
 
7
9
  @@instance = nil # An instance to Encryption::Symmetric
data/lib/helpers.rb CHANGED
@@ -0,0 +1 @@
1
+ require_relative 'helpers/string.rb'
@@ -0,0 +1,35 @@
1
+ module Encryption
2
+ module String
3
+
4
+ def encrypt(options = {})
5
+ encryptor(options).encrypt self
6
+ end
7
+
8
+ def decrypt(options = {})
9
+ encryptor(options).decrypt self
10
+ end
11
+
12
+ def encrypt!(options = {})
13
+ replace encrypt(options)
14
+ end
15
+
16
+ def decrypt!(options = {})
17
+ replace decrypt(options)
18
+ end
19
+
20
+ private
21
+
22
+ def encryptor(options)
23
+ return Encryption if options.empty?
24
+
25
+ encrypt = Encryption::Symmetric.new
26
+
27
+ options.each do |key, value|
28
+ encrypt.send(key.to_s + '=', value)
29
+ end
30
+
31
+ encrypt
32
+ end
33
+
34
+ end
35
+ end
@@ -19,8 +19,8 @@ describe Encryption do
19
19
  Encryption.cipher.should == cipher
20
20
  end
21
21
 
22
- OpenSSL::Cipher.ciphers.each do |cipher|
23
- next if ! cipher[-3, 3].nil? and ['gcm', 'fb1'].include? cipher[-3, 3].downcase
22
+ %x(openssl list-cipher-commands).split.each do |cipher|
23
+ next if ['base64', 'zlib'].include? cipher
24
24
 
25
25
  describe 'with cipher ' + cipher do
26
26
  before(:each) do
@@ -21,8 +21,9 @@ describe Encryption::Symmetric do
21
21
  encryptor.cipher.should == cipher
22
22
  end
23
23
 
24
- OpenSSL::Cipher.ciphers.each do |cipher|
25
- next if ! cipher[-3, 3].nil? and ['gcm', 'fb1'].include? cipher[-3, 3].downcase
24
+ %x(openssl list-cipher-commands).split.each do |cipher|
25
+ next if ['base64', 'zlib'].include? cipher
26
+
26
27
  describe 'with cipher ' + cipher do
27
28
 
28
29
  before(:each) do
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+
5
+ it { should respond_to :encrypt }
6
+ it { should respond_to :decrypt }
7
+ it { should respond_to :encrypt! }
8
+ it { should respond_to :decrypt! }
9
+
10
+ describe "with global Encryption instance" do
11
+ before(:each) do
12
+ @string = String.random
13
+ Encryption.key = String.random
14
+ end
15
+
16
+ it 'should generate encryption different then the original string' do
17
+ @string.encrypt.should_not == @string
18
+ end
19
+
20
+ it 'should decrypt, encrypted values and match the original string' do
21
+ @string.encrypt.decrypt.should == @string
22
+ end
23
+ end
24
+
25
+ describe "with custom options" do
26
+ before(:each) do
27
+ @string = String.random
28
+ @options = {
29
+ :key => String.random,
30
+ :iv => String.random
31
+ }
32
+ end
33
+
34
+ it 'should generate encryption different then the original string' do
35
+ @string.encrypt(@options).should_not == @string
36
+ end
37
+
38
+ it 'should decrypt, encrypted values and match the original string' do
39
+ @string.encrypt(@options).decrypt(@options).should == @string
40
+ end
41
+ end
42
+
43
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encryption
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Itay Grudev
@@ -12,7 +11,7 @@ cert_chain: []
12
11
  date: 2013-03-30 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Encryption provides a simple interface for symmetric / asymmetric encryption
15
- and decryption with the OpenSSL Cipher library
14
+ with the OpenSSL Cipher library
16
15
  email:
17
16
  - itay.grudev@gmail.com
18
17
  executables: []
@@ -32,6 +31,7 @@ files:
32
31
  - lib/configuration/symmetric.rb
33
32
  - lib/encryption.rb
34
33
  - lib/helpers.rb
34
+ - lib/helpers/string.rb
35
35
  - lib/modules.rb
36
36
  - lib/modules/asymmetric.rb
37
37
  - lib/modules/asymmetric/keypair.rb
@@ -48,30 +48,30 @@ files:
48
48
  - spec/encryption/asymmetric/public_key_spec.rb
49
49
  - spec/encryption/symmetric_global_spec.rb
50
50
  - spec/encryption/symmetric_instance_spec.rb
51
+ - spec/helpers/string_spec.rb
51
52
  - spec/spec_helper.rb
52
53
  homepage: https://github.com/Itehnological/encryption
53
54
  licenses:
54
55
  - MIT
56
+ metadata: {}
55
57
  post_install_message:
56
58
  rdoc_options: []
57
59
  require_paths:
58
60
  - lib
59
61
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
62
  requirements:
62
63
  - - ! '>='
63
64
  - !ruby/object:Gem::Version
64
65
  version: '0'
65
66
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
67
  requirements:
68
68
  - - ! '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 1.8.25
73
+ rubygems_version: 2.0.3
74
74
  signing_key:
75
- specification_version: 3
75
+ specification_version: 4
76
76
  summary: A simple wrapper for the OpenSSL Cipher library
77
77
  test_files: []