parsel 0.1.0

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.
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ parsel (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rake (0.9.2.2)
11
+ rspec (2.10.0)
12
+ rspec-core (~> 2.10.0)
13
+ rspec-expectations (~> 2.10.0)
14
+ rspec-mocks (~> 2.10.0)
15
+ rspec-core (2.10.0)
16
+ rspec-expectations (2.10.0)
17
+ diff-lcs (~> 1.1.3)
18
+ rspec-mocks (2.10.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ parsel!
25
+ rake
26
+ rspec
@@ -0,0 +1,47 @@
1
+ # parsel
2
+
3
+ Encrypt and decrypt data with a given key.
4
+
5
+ This library was created to allow an easy data
6
+ exchange between Ruby and Node.js.
7
+
8
+ Check it out the Node.js counter-part: <http://github.com/fnando/parsel-js>.
9
+
10
+ ## Installation
11
+
12
+ gem install parsel
13
+
14
+ ## Usage
15
+
16
+ require "parsel"
17
+
18
+ secret_key = "mysupersecretkeythatnobodyknowsabout"
19
+ encrypted = Parsel.encrypt(secret_key, "hello from ruby!")
20
+ decrypted = Parsel.decrypt(secret_key, encrypted)
21
+
22
+ ## Maintainer
23
+
24
+ - Nando Vieira (<http://nandovieira.com.br>)
25
+
26
+ ## License
27
+
28
+ (The MIT License)
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining
31
+ a copy of this software and associated documentation files (the
32
+ 'Software'), to deal in the Software without restriction, including
33
+ without limitation the rights to use, copy, modify, merge, publish,
34
+ distribute, sublicense, and/or sell copies of the Software, and to
35
+ permit persons to whom the Software is furnished to do so, subject to
36
+ the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be
39
+ included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
42
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,32 @@
1
+ require "openssl"
2
+ require "base64"
3
+
4
+ module Parsel
5
+ autoload :Version, "parsel/version"
6
+
7
+ def self.encrypt(key, data)
8
+ encode cipher(:encrypt, key, data)
9
+ end
10
+
11
+ def self.decrypt(key, data)
12
+ cipher(:decrypt, key, decode(data))
13
+ rescue Exception
14
+ false
15
+ end
16
+
17
+ private
18
+ def self.cipher(mode, key, data)
19
+ cipher = OpenSSL::Cipher.new("AES-256-CBC").public_send(mode)
20
+ cipher.key = Digest::SHA256.digest(key)
21
+ cipher.iv = "f89209ffcdd1a225"
22
+ cipher.update(data) + cipher.final
23
+ end
24
+
25
+ def self.encode(data)
26
+ Base64.encode64(data).chomp
27
+ end
28
+
29
+ def self.decode(data)
30
+ Base64.decode64(data).chomp
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ module Parsel
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "parsel/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "parsel"
7
+ s.version = Parsel::Version::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nando Vieira"]
10
+ s.email = ["fnando.vieira@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/parsel"
12
+ s.summary = "Encrypt and decrypt data with a given key."
13
+ s.description = s.summary
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "rake"
21
+ s.add_development_dependency "rspec"
22
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe Parsel do
4
+ let(:key) { "my secret key" }
5
+
6
+ it "encrypts data" do
7
+ Parsel.encrypt(key, "hello").should_not eql("hello")
8
+ end
9
+
10
+ it "decrypts data" do
11
+ encrypted = Parsel.encrypt(key, "hello")
12
+ Parsel.decrypt(key, encrypted).should eql("hello")
13
+ end
14
+
15
+ it "returns false when decryption fails" do
16
+ Parsel.decrypt("abc", "123").should be_false
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ require "bundler"
2
+ Bundler.setup(:default, :development)
3
+ Bundler.require
4
+
5
+ require "parsel"
6
+
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parsel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nando Vieira
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Encrypt and decrypt data with a given key.
47
+ email:
48
+ - fnando.vieira@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - README.md
58
+ - Rakefile
59
+ - lib/parsel.rb
60
+ - lib/parsel/version.rb
61
+ - parsel.gemspec
62
+ - spec/parsel_spec.rb
63
+ - spec/spec_helper.rb
64
+ homepage: http://rubygems.org/gems/parsel
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: -2861301194384926931
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ segments:
86
+ - 0
87
+ hash: -2861301194384926931
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.23
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Encrypt and decrypt data with a given key.
94
+ test_files:
95
+ - spec/parsel_spec.rb
96
+ - spec/spec_helper.rb