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 +4 -4
- data/.travis.yml +6 -0
- data/CHANGELOG.md +3 -0
- data/README.md +56 -0
- data/cryptosystem.gemspec +11 -2
- data/lib/cryptosystem.rb +1 -0
- data/lib/cryptosystem/rsa.rb +2 -0
- data/lib/cryptosystem/version.rb +3 -0
- data/test/cryptosystem/rsa_test.rb +4 -8
- data/test/test_helper.rb +5 -1
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85f438691a896bf64fe02231dd5af6186823a5b6
|
4
|
+
data.tar.gz: 3699e93c8c639527d01d76316d09ddd36a792cde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66f44adf68b69c9a90d4dac52aba7bed93fb7454ca772f8a15a8ffa8157fbf38bdc5b400b548f4515dea5f2de3c4740cd8070565cfdb21e7f84701ed88e9eb48
|
7
|
+
data.tar.gz: d504380686a8ebadd9761e2e93ea9464b980641e4aafa120c12531b270ccc78b645d8e1ff093a2c4e0da4df3d3161c2e05a1bfbee3ad510b363fec1a12f24547
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
[](https://badge.fury.io/rb/cryptosystem)
|
2
|
+
[](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 =
|
8
|
+
s.version = Cryptosystem::VERSION
|
4
9
|
s.files = `git ls-files`.split($/)
|
5
|
-
s.summary = '
|
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
data/lib/cryptosystem/rsa.rb
CHANGED
@@ -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
|
@@ -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
|
33
|
-
|
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
|
39
|
-
|
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
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.
|
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-
|
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:
|
60
|
+
summary: Simple asymmetric (public-key) encryption.
|
55
61
|
test_files: []
|