cryptosystem 0.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f81553a727d6fa1eaa44385bdf8e2086b7c09f9
4
- data.tar.gz: f1077b92847b5136fd53dd548041dc9e33b3f338
3
+ metadata.gz: 85f438691a896bf64fe02231dd5af6186823a5b6
4
+ data.tar.gz: 3699e93c8c639527d01d76316d09ddd36a792cde
5
5
  SHA512:
6
- metadata.gz: 1630aab91d71c11266a1509230b59ce8e19e354e53b0374d09c1712ecf893ebf1b5d739e4300e178c9592671c19155efe0e0ce7dedf22c77321ed69a62f04db4
7
- data.tar.gz: f677b47d6486ddd6ee6487101a0a3cd2fb8f39882a25b6ace6c8f25ef3d231d46b75616125765f319675993077b8ccae7c148c91a61c1ce67446b9ccba686f80
6
+ metadata.gz: 66f44adf68b69c9a90d4dac52aba7bed93fb7454ca772f8a15a8ffa8157fbf38bdc5b400b548f4515dea5f2de3c4740cd8070565cfdb21e7f84701ed88e9eb48
7
+ data.tar.gz: d504380686a8ebadd9761e2e93ea9464b980641e4aafa120c12531b270ccc78b645d8e1ff093a2c4e0da4df3d3161c2e05a1bfbee3ad510b363fec1a12f24547
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ #### 0.0.1
2
+ * Encrypting a `nil` value returns `nil` instead of `EncryptError`.
3
+ * Decrypting a `nil` value returns `nil` instead of `DecryptError`.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ [![Gem Version](https://badge.fury.io/rb/cryptosystem.svg)](https://badge.fury.io/rb/cryptosystem)
2
+ [![Build Status](https://travis-ci.org/jdubswe/cryptosystem.svg?branch=master)](https://travis-ci.org/jdubswe/cryptosystem)
3
+
4
+ # Cryptosystem
5
+ Cryptosystem is a Ruby library facilitating simple encryption and decryption with asymmetric cryptography (or public-key
6
+ cryptography). At this time, only RSA is supported.
7
+
8
+ ## Installation
9
+ In your Gemfile, include the `cryptosystem` gem and then `bundle install`.
10
+
11
+ ```ruby
12
+ gem 'cryptosystem'
13
+ ```
14
+
15
+ ## Getting Started
16
+ In order to encrypt and decrypt, a public and private key must be generated.
17
+
18
+ ```bash
19
+ $ openssl genrsa -out private.key
20
+ $ openssl rsa -in private.key -pubout > public.pub
21
+ ```
22
+
23
+ ## Configuration
24
+ Cryptosystem must know the path and password to your private key as well as the path to your public key.
25
+
26
+ ```ruby
27
+ # config/initializers/cryptosystem.rb
28
+
29
+ Cryptosystem::RSA.configure do |config|
30
+ config.password = ENV['secret-password']
31
+ config.private_key_path = 'path/to/private.key'
32
+ config.public_key_path = 'path/to/public.pub'
33
+ end
34
+ ```
35
+
36
+ ## Encrypting
37
+ After generating a key pair and properly configuring Cryptosystem, encryption is straightforward.
38
+
39
+ ```ruby
40
+ rsa = Cryptosystem::RSA.new
41
+ rsa.encrypt('secret') # => "JxpuhTpEqRtMLmaSfaq/X6XONkBnMe..."
42
+ ```
43
+
44
+ The encrypted value is Base64 encoded, making it suitable for database storage.
45
+
46
+ ## Decrypting
47
+ Decrypting is as simple as passing in an encrypted, Base64 encoded value.
48
+
49
+ ```ruby
50
+ rsa = Cryptosystem::RSA.new
51
+ encrypted_value = rsa.encrypt('secret') # => "Y8DWJc2/+7TIxdLEolV99XI2sclHuK..."
52
+ rsa.decrypt(encrypted_value) # => "secret"
53
+ ```
54
+
55
+ ## Acknowledgments
56
+ Special thanks to [@jedspurg](https://github.com/jedspurg) for the inspiration for this project.
data/cryptosystem.gemspec CHANGED
@@ -1,8 +1,17 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cryptosystem/version'
5
+
1
6
  Gem::Specification.new do |s|
2
7
  s.name = 'cryptosystem'
3
- s.version = '0.0.0'
8
+ s.version = Cryptosystem::VERSION
4
9
  s.files = `git ls-files`.split($/)
5
- s.summary = 'Asymmetric encryption'
10
+ s.summary = 'Simple asymmetric (public-key) encryption.'
11
+ s.description = <<-DESC
12
+ Cryptosystem is a Ruby library facilitating simple encryption and
13
+ decryption with asymmetric cryptography (or public-key cryptography).
14
+ DESC
6
15
  s.author = 'Josh Wetzel'
7
16
  s.license = 'MIT'
8
17
  s.required_ruby_version = '~> 2'
data/lib/cryptosystem.rb CHANGED
@@ -4,3 +4,4 @@ require 'openssl'
4
4
  require 'cryptosystem/base'
5
5
  require 'cryptosystem/exceptions'
6
6
  require 'cryptosystem/rsa'
7
+ require 'cryptosystem/version'
@@ -19,12 +19,14 @@ module Cryptosystem
19
19
  end
20
20
 
21
21
  def encrypt(value)
22
+ return nil if value.nil?
22
23
  base64_encode(public_key.public_encrypt(value))
23
24
  rescue => error
24
25
  raise EncryptError, error.message
25
26
  end
26
27
 
27
28
  def decrypt(value)
29
+ return nil if value.nil?
28
30
  private_key.private_decrypt(base64_decode(value))
29
31
  rescue => error
30
32
  raise DecryptError, error.message
@@ -0,0 +1,3 @@
1
+ module Cryptosystem
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -29,15 +29,11 @@ class RSATest < Minitest::Test
29
29
  assert Base64.strict_encode64(@rsa.decrypt(@rsa.encrypt('test')))
30
30
  end
31
31
 
32
- def test_bad_encrypt_raises_exception
33
- assert_raises Cryptosystem::EncryptError do
34
- @rsa.encrypt(nil)
35
- end
32
+ def test_encrypting_nil_value_returns_nil
33
+ assert_nil @rsa.encrypt(nil)
36
34
  end
37
35
 
38
- def test_bad_decrypt_raises_exception
39
- assert_raises Cryptosystem::DecryptError do
40
- @rsa.decrypt(nil)
41
- end
36
+ def test_decrypting_nil_value_returns_nil
37
+ assert_nil @rsa.decrypt(nil)
42
38
  end
43
39
  end
data/test/test_helper.rb CHANGED
@@ -1,5 +1,9 @@
1
- require 'minitest/autorun'
2
1
  require 'cryptosystem'
2
+ require 'minitest/autorun'
3
+
4
+ if !defined?(Minitest::Test)
5
+ Minitest::Test = MiniTest::Unit::TestCase
6
+ end
3
7
 
4
8
  Cryptosystem::RSA.configure do |config|
5
9
  config.password = 'test'
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptosystem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Wetzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-14 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description: |2
14
+ Cryptosystem is a Ruby library facilitating simple encryption and
15
+ decryption with asymmetric cryptography (or public-key cryptography).
14
16
  email:
15
17
  executables: []
16
18
  extensions: []
17
19
  extra_rdoc_files: []
18
20
  files:
19
21
  - ".gitignore"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
20
24
  - LICENSE
25
+ - README.md
21
26
  - Rakefile
22
27
  - cryptosystem.gemspec
23
28
  - lib/cryptosystem.rb
24
29
  - lib/cryptosystem/base.rb
25
30
  - lib/cryptosystem/exceptions.rb
26
31
  - lib/cryptosystem/rsa.rb
32
+ - lib/cryptosystem/version.rb
27
33
  - test/cryptosystem/rsa_test.rb
28
34
  - test/keys/rsa.key
29
35
  - test/keys/rsa.pub
@@ -51,5 +57,5 @@ rubyforge_project:
51
57
  rubygems_version: 2.5.1
52
58
  signing_key:
53
59
  specification_version: 4
54
- summary: Asymmetric encryption
60
+ summary: Simple asymmetric (public-key) encryption.
55
61
  test_files: []