encrypt 0.0.4

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: 9a94e5efdc1e79b835acdff5b9743e3c208e13ca
4
+ data.tar.gz: cda360aca0e6655502efbb005a8db0953d52ca69
5
+ SHA512:
6
+ metadata.gz: 1f216b368a139c7664248e994576c81384697d9384b3bf8f9a049199da4561861162285b8802fd533caeeb4b80257213ec775e9b6a4f093b7fe82a280cb1a970
7
+ data.tar.gz: 14ba9a4609255e5c4564349b9d86192f25ff321f2a7018dd24f2be6f4104d6e9ed47d4a49078697b1d38a62d83087a42624f76f42285261d68b5572ddd87a833
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Shannon Skipper
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,36 @@
1
+ # Encrypt
2
+
3
+ Simply encrypt and decrypt strings with AES-256.
4
+
5
+ Encrypt uses Ruby 2.0's experimental refinements to extend String locally to add the #encrypt and #decrypt methods. Activate the refinement with using: `using Encrypt`.
6
+
7
+ Encrypt uses an AES-256 cipher in CTR mode. A randomly generated salt and IV are publicly stored as the 32 bytes preceding the encrypted data.
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ require 'encrypt'
13
+
14
+ using Encrypt
15
+
16
+ encrypted = 'sekret msg'.encrypt 'passw0rd'
17
+ #=> "\xFDB\xDF@b\xD0\xB8>\xFD\xFE"
18
+
19
+ encrypted.decrypt 'passw0rd'
20
+ #=> "sekret msg"
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ $ gem install encrypt
26
+
27
+ ## Requirements
28
+
29
+ Ruby 2.0.0+ (uses [experimental refinements](http://www.ruby-doc.org/core-2.0/doc/syntax/refinements_rdoc.html))
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Commit changes
35
+ 3. Submit a Pull Request
36
+ 4. :cake:
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+
3
+ task default: [:test]
4
+
5
+ Rake::TestTask.new do |test|
6
+ test.pattern = 'test/*_test.rb'
7
+ end
data/encrypt.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ require File.join(File.expand_path('../lib', __FILE__), 'encrypt/version')
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'encrypt'
6
+ spec.version = Encrypt::VERSION
7
+ spec.authors = ['Shannon Skipper']
8
+ spec.email = ['shannonskipper@gmail.com']
9
+ spec.description = %q{A gem for encrypting and decrypting a String with AES-256. Just supply the password.}
10
+ spec.summary = %q{Encrypts and decrypts strings with AES-256 in CTR mode. Encrypt uses Ruby 2.0's experimental refinements to extend String locally to add the #encrypt and #decrypt methods.}
11
+ spec.homepage = 'https://github.com/havenwood/encrypt#readme'
12
+ spec.license = 'MIT'
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_development_dependency 'bundler'
19
+ spec.add_development_dependency 'rake'
20
+ end
data/lib/encrypt.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'openssl'
2
+
3
+ module Encrypt
4
+ refine String do
5
+ def encrypt key
6
+ cipher = OpenSSL::Cipher::AES256.new(:CTR)
7
+ cipher.encrypt
8
+ iv = cipher.random_iv
9
+ salt = OpenSSL::Random.random_bytes(16)
10
+ cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
11
+ salt << iv << cipher.update(self) << cipher.final
12
+ end
13
+
14
+ def decrypt key
15
+ cipher = OpenSSL::Cipher::AES256.new(:CTR)
16
+ cipher.decrypt
17
+ salt = self.byteslice(0..15)
18
+ cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
19
+ cipher.iv = self.byteslice(16..31)
20
+ cipher.update(self.byteslice(32..-1)) << cipher.final
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Encrypt
2
+ VERSION = '0.0.4'
3
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../lib/encrypt'
2
+ require 'minitest/autorun'
3
+ require 'minitest/pride'
4
+
5
+ using Encrypt
6
+
7
+ describe Encrypt do
8
+ before do
9
+ @encrypted = 'sekret'.encrypt('passw0rd')
10
+ end
11
+
12
+ it 'encrypts' do
13
+ @encrypted.bytes.count == 38
14
+ end
15
+
16
+ it 'decrypts' do
17
+ assert_equal 'sekret', @encrypted.decrypt('passw0rd')
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: encrypt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Shannon Skipper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
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: rake
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: A gem for encrypting and decrypting a String with AES-256. Just supply
42
+ the password.
43
+ email:
44
+ - shannonskipper@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - encrypt.gemspec
55
+ - lib/encrypt.rb
56
+ - lib/encrypt/version.rb
57
+ - test/encrypt_test.rb
58
+ homepage: https://github.com/havenwood/encrypt#readme
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: '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.0.4
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: 'Encrypts and decrypts strings with AES-256 in CTR mode. Encrypt uses Ruby
82
+ 2.0''s experimental refinements to extend String locally to add the #encrypt and
83
+ #decrypt methods.'
84
+ test_files:
85
+ - test/encrypt_test.rb
86
+ has_rdoc: