scrambled_eggs 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00918a1d8247634f603466e782d2f3b8693c928d
4
+ data.tar.gz: e7a799fb131c57bd9d46f77ec78f39c1e243f09d
5
+ SHA512:
6
+ metadata.gz: 482fbb5c9e2c015533d23234997ed4dfbcec5602fa94523fdd7076c6bd4021e011297f6238618aa0467f5aa4aa18aab1e324b0327282d244c60377324e3cba75
7
+ data.tar.gz: 1e40b041b795677c0a557c7b355717ffef77e4f442fe489fb6e37bf365ea7eeed2fa3609ce810bbb62b0dd13661a3b5a2a3fd34c28c150501e831119581c9c02
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg
2
+ doc/
3
+ Gemfile.lock
4
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scrambled_eggs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 sanadan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # scrambled_eggs
2
+
3
+ Easy data scrambler
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'scrambled_eggs'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install scrambled_eggs
20
+
21
+ ## Usage
22
+
23
+ Default key is **/etc/hostname** file.
24
+
25
+ ### Scramble (encrypt)
26
+ ```Ruby
27
+ egg = ScrambledEggs.new
28
+ scrambled = egg.scramble( data )
29
+ ```
30
+
31
+ ### Descramble (decrypt)
32
+ ```Ruby
33
+ egg = ScrambledEggs.new
34
+ descrambled = egg.descramble( scrambled )
35
+ ```
36
+
37
+ ### Advanced
38
+ ```Ruby
39
+ egg = ScrambledEggs.new( algorithm: 'aes-128-cbc', key: 'Password' )
40
+ scrambled = egg.scramble( data )
41
+ descrambled = egg.descramble( scrambled )
42
+ ```
43
+
44
+ ## Copyright
45
+
46
+ Author:
47
+
48
+ * sanadan <jecy00@gmail.com>
49
+
50
+ Copyright:
51
+
52
+ * Copyright (c) 2015 sanadan
53
+
54
+ License:
55
+
56
+ * MIT
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/sanadan/scrambled_eggs/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
65
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/*_test.rb']
7
+ end
8
+
9
+ task :default => [ :install, :test ]
10
+
@@ -0,0 +1,3 @@
1
+ class ScrambledEggs
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,48 @@
1
+ require "scrambled_eggs/version"
2
+ require 'bundler/setup'
3
+ Bundler.require
4
+
5
+ # Easy data scrambler by OpenSSL
6
+ class ScrambledEggs
7
+ # Initialize
8
+ #
9
+ # _algorithm_ :: Algorithm
10
+ # _salt_ :: Salt (8 bytes)
11
+ # _key_ :: Crypt key
12
+ def initialize( algorithm: 'aes-256-cbc', salt: nil, key: nil )
13
+ @@algorithm = algorithm
14
+ @@salt = salt ? salt : OpenSSL::Random.random_bytes( 8 )
15
+ if key
16
+ @@key = key
17
+ else
18
+ @@key = File.open( '/etc/hostname' ).read
19
+ end
20
+ end
21
+
22
+ # Encrypt data
23
+ #
24
+ # _data_ :: Data for encrypt
25
+ #
26
+ # return :: Crypted data
27
+ def scramble( data )
28
+ cipher = OpenSSL::Cipher::Cipher.new( @@algorithm )
29
+ cipher.encrypt
30
+ cipher.pkcs5_keyivgen( @@key, @@salt )
31
+ @@salt + cipher.update( data ) + cipher.final
32
+ end
33
+
34
+ # Descrypt data
35
+ #
36
+ # _scrambled_ :: Data for decrypt
37
+ #
38
+ # return :: Decrypted data
39
+ def descramble( scrambled )
40
+ cipher = OpenSSL::Cipher::Cipher.new( @@algorithm )
41
+ cipher.decrypt
42
+ salt = scrambled[ 0, 8 ]
43
+ data = scrambled[ 8, scrambled.size ]
44
+ cipher.pkcs5_keyivgen( @@key, salt )
45
+ cipher.update( data ) + cipher.final
46
+ end
47
+ end
48
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'scrambled_eggs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scrambled_eggs"
8
+ spec.version = ScrambledEggs::VERSION
9
+ spec.authors = ["sanadan"]
10
+ spec.email = ["jecy00@gmail.com"]
11
+ spec.summary = %q{Easy data scrambler.}
12
+ spec.description = %q{Easy data Scrambler. Default by hostname.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency 'test-unit'
23
+
24
+ spec.required_ruby_version = '>= 2.0.0'
25
+ end
@@ -0,0 +1,48 @@
1
+ =begin
2
+ require "tmpdir"
3
+ require "pathname"
4
+
5
+ class Pathname
6
+ @@tempname_number = 0
7
+ def self.tempname(base=$0, dir=Dir.tmpdir)
8
+ @@tempname_number += 1
9
+ path = new(dir) + "#{File.basename(base)}.#{$$}.#{@@tempname_number}"
10
+ at_exit do
11
+ path.rmtree if path.exist?
12
+ end
13
+ path
14
+ end
15
+ end
16
+ =end
17
+
18
+ require File.dirname(__FILE__) + '/test_helper.rb'
19
+
20
+ class ScrambledEggsTest < Test::Unit::TestCase
21
+ def test_scramble_text
22
+ text = 'Test text'
23
+ egg = ScrambledEggs.new
24
+ scrambled = egg.scramble( text )
25
+ assert_equal( egg.descramble( scrambled ), text )
26
+ end
27
+ def test_scramble_binary
28
+ size = OpenSSL::BN.rand_range( 4096 ) + 1
29
+ data = OpenSSL::Random.random_bytes( size )
30
+ egg = ScrambledEggs.new
31
+ scrambled = egg.scramble( data )
32
+ assert_equal( egg.descramble( scrambled ), data )
33
+ end
34
+ def test_scramble
35
+ text = 'Test texti 2'
36
+ egg = ScrambledEggs.new( algorithm: 'aes-128-cbc', salt: '01234567', key: 'Test key' )
37
+ scrambled = egg.scramble( text )
38
+ # puts scrambled.unpack( 'H*' )
39
+ assert_equal( scrambled, [ '30313233343536371c24bce6e1bc9562162f4625602fb608' ].pack( 'H*' ) )
40
+ assert_equal( egg.descramble( scrambled ), text )
41
+ end
42
+ def test_another_eggs
43
+ text = 'Test text 3'
44
+ scrambled = ScrambledEggs.new.scramble( text )
45
+ assert_equal( ScrambledEggs.new.descramble( scrambled ), text )
46
+ end
47
+ end
48
+
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/scrambled_eggs'
3
+
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrambled_eggs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - sanadan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Easy data Scrambler. Default by hostname.
42
+ email:
43
+ - jecy00@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/scrambled_eggs.rb
54
+ - lib/scrambled_eggs/version.rb
55
+ - scrambled_eggs.gemspec
56
+ - test/scrambled_eggs_test.rb
57
+ - test/test_helper.rb
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.0.0
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.5
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Easy data scrambler.
82
+ test_files:
83
+ - test/scrambled_eggs_test.rb
84
+ - test/test_helper.rb