cryptic 1.0.0.beta.6 → 1.0.0.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/README.md +8 -8
- data/bin/cryptic +5 -1
- data/cryptic_private.pem +30 -0
- data/cryptic_public.pem +9 -0
- data/lib/cryptic/encrypted_data.rb +1 -0
- data/lib/cryptic/exceptions/incorrect_passphrase.rb +9 -0
- data/lib/cryptic/exceptions/invalid_key.rb +8 -0
- data/lib/cryptic/exceptions.rb +2 -0
- data/lib/cryptic/keypair.rb +66 -12
- data/lib/cryptic/version.rb +1 -1
- data/locales/files/README.en.md +50 -0
- data/locales/files/README.es.md +52 -0
- data/spec/keypair_spec.rb +79 -0
- metadata +11 -5
- data/spec/default_spec.rb +0 -1
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Just run: `gem install cryptic` or add `gem 'cryptic'` to your Gemfile.
|
|
11
11
|
### Command line
|
12
12
|
|
13
13
|
```
|
14
|
-
[ecarey @ cryptic]$ cryptic
|
14
|
+
[ecarey @ cryptic]$ cryptic
|
15
15
|
Commands:
|
16
16
|
cryptic decrypt [PRIVATE_KEY] [ENCRYPTED_FILE] [OPTIONS] # Decrypt a file with a private key
|
17
17
|
cryptic encrypt [PUBLIC_KEY] [TEXT_FILE] [OPTIONS] # Encrypt a file with a public key
|
@@ -24,22 +24,22 @@ Commands:
|
|
24
24
|
```ruby
|
25
25
|
require 'cryptic'
|
26
26
|
|
27
|
-
#
|
28
|
-
keypair = Cryptic::Keypair.new('
|
29
|
-
keypair.save("#{ENV['HOME']}/.cryptic_keys")
|
27
|
+
# Load a keypair to use:
|
28
|
+
keypair = Cryptic::Keypair.new('cryptic_private.pem', public_key: 'cryptic_public.pem')
|
30
29
|
|
30
|
+
# Obtain your public/private keys from the `Cryptic::Keypair` object:
|
31
31
|
private_key = keypair.private_key
|
32
32
|
public_key = keypair.public_key
|
33
33
|
|
34
34
|
# Encrypt a file:
|
35
35
|
data = File.read('foo.txt')
|
36
|
-
encrypted = Cryptic::EncryptedData.new(data, public_key)
|
36
|
+
encrypted = Cryptic::EncryptedData.new(data, public_key, :base64)
|
37
37
|
|
38
|
-
# Returns an encrypted string you can save off to a file
|
38
|
+
# Returns an encrypted string you can save off to a file:
|
39
39
|
encrypted.data
|
40
40
|
|
41
|
-
# To return the data call decrypt on the encrypted data object w/ the private key and passphrase
|
42
|
-
decrypted = encrypted.decrypt(private_key, 'P4$SpHr4z3')
|
41
|
+
# To return the data call decrypt on the encrypted data object w/ the private key and passphrase:
|
42
|
+
decrypted = encrypted.decrypt(private_key, 'P4$SpHr4z3', :base64)
|
43
43
|
```
|
44
44
|
## Contributing
|
45
45
|
|
data/bin/cryptic
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
require 'cryptic'
|
6
6
|
require 'thor'
|
7
7
|
|
8
|
+
# TODO: Add support for localized descriptions
|
9
|
+
# TODO: Add support for localized alias of commands in locales that share the
|
10
|
+
# English alphabet?
|
11
|
+
|
8
12
|
class CrypticCLI < Thor
|
9
13
|
desc 'decrypt [PRIVATE_KEY] [ENCRYPTED_FILE] [OPTIONS]', 'Decrypt a file with a private key'
|
10
14
|
method_option :passphrase, aliases: %w[-p], default: nil, desc: 'The passphrase to unlock the private key with'
|
@@ -53,7 +57,7 @@ class CrypticCLI < Thor
|
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
56
|
-
desc 'generate [OPTIONS]', 'Generate a private/public keypair'
|
60
|
+
desc 'generate [OPTIONS]', 'Generate a private/public keypair'
|
57
61
|
method_option :bits, aliases: %w[-b size], default: 2048, desc: 'The number of bits to use when generating your key'
|
58
62
|
method_option :passphrase, aliases: %w[-p], default: nil, desc: 'The passphrase to generate the private key with'
|
59
63
|
method_option :path, aliases: %w[-o], default: '.', desc: 'Where to place the generated keys'
|
data/cryptic_private.pem
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
Proc-Type: 4,ENCRYPTED
|
3
|
+
DEK-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cDcsSwdgMKGz4YQR64RC6c98s/c0HZQzPj
|
5
|
+
vEQPA/fU0LoFmGynZ9/pdEXQe6N3kzbpG8//64RxgFPco7g7HbZIVaRqyx3U4UgQ
|
6
|
+
FKb+HoYDs5U+P6qz6TU4YFZbqglunptxKIjUZG7lywGPtDhD9gQf2n5n+wId4MgD
|
7
|
+
xKwrj+ZQF220Mmq96LSm1a3BtiRhZInKLPn9Yr7JFh7CgVmqn2/50UVAbbdKKO4x
|
8
|
+
TwIDAQAB
|
9
|
+
-----END PUBLIC KEY-----
|
@@ -46,6 +46,7 @@ module Cryptic
|
|
46
46
|
# Creates a new encrypted data object from an encrypted data string
|
47
47
|
#
|
48
48
|
# @param [String] data the encrypted data to load
|
49
|
+
# @param [Symbol] encoding the encoding to use
|
49
50
|
# @return [EncryptedData] an encrypted data object
|
50
51
|
def self.load(data, encoding = :none)
|
51
52
|
new(data, nil, encoding)
|
data/lib/cryptic/exceptions.rb
CHANGED
@@ -2,6 +2,8 @@ require 'colorize'
|
|
2
2
|
require 'cryptic/exceptions/decryption_error'
|
3
3
|
require 'cryptic/exceptions/encryption_error'
|
4
4
|
require 'cryptic/exceptions/invalid_data'
|
5
|
+
require 'cryptic/exceptions/invalid_key'
|
6
|
+
require 'cryptic/exceptions/incorrect_passphrase'
|
5
7
|
require 'cryptic/exceptions/key_generation_failure'
|
6
8
|
require 'cryptic/exceptions/key_mismatch'
|
7
9
|
require 'cryptic/exceptions/key_not_found'
|
data/lib/cryptic/keypair.rb
CHANGED
@@ -8,27 +8,81 @@ module Cryptic
|
|
8
8
|
|
9
9
|
# A class that represents a private and public keypair
|
10
10
|
#
|
11
|
-
# @!attribute [String] private_key the contents of the private key file
|
12
|
-
# @!attribute [String] public_key the contents of the public key file
|
13
11
|
# @author Erran Carey <me@errancarey.com>
|
14
12
|
class Keypair
|
15
|
-
|
16
|
-
|
13
|
+
attr_accessor :private_key
|
14
|
+
attr_accessor :public_key
|
15
|
+
|
16
|
+
# Initializes a Cryptic::Keypair object from a private/public keypair
|
17
|
+
#
|
18
|
+
# @note The passphrase isn't saved
|
19
|
+
# @todo Use the Ruby 2 named parameters syntax vs. an opts hash
|
20
|
+
# @todo Validate that keys are public/private
|
21
|
+
# @param [String] private_key the private key (or file) to use
|
22
|
+
# @param [Hash] opts additional options to configure your Keypair with
|
23
|
+
# @option opts [String] public_key the public key (or file) to use
|
24
|
+
# @option opts [String] passphrase the passphrase to determine the public key
|
25
|
+
# from
|
26
|
+
# @return [Keypair] the initialized Cryptic::Keypair object
|
27
|
+
def initialize(private_key, opts = { public_key: nil, passphrase: nil })
|
28
|
+
@private_key = OpenSSL::PKey::RSA.new(
|
29
|
+
if File.exists?(private_key)
|
30
|
+
File.read(private_key)
|
31
|
+
else
|
32
|
+
private_key
|
33
|
+
end,
|
34
|
+
opts[:passphrase]
|
35
|
+
)
|
36
|
+
|
37
|
+
unless @private_key.private?
|
38
|
+
raise(
|
39
|
+
Cryptic::InvalidKey,
|
40
|
+
"Public key '#{private_key}' provided as a private key."
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
@public_key = OpenSSL::PKey::RSA.new(
|
45
|
+
if opts[:public_key] && File.exists?(opts[:public_key])
|
46
|
+
File.read(opts[:public_key])
|
47
|
+
elsif opts[:public_key]
|
48
|
+
opts[:public_key]
|
49
|
+
else
|
50
|
+
@private_key
|
51
|
+
end,
|
52
|
+
opts[:passphrase]
|
53
|
+
).public_key
|
54
|
+
rescue OpenSSL::PKey::RSAError => e
|
55
|
+
if e.message.eql? 'Neither PUB key nor PRIV key:: not enough data'
|
56
|
+
if @private_key.nil?
|
57
|
+
raise Cryptic::InvalidKey, "Invalid private key: #{private_key}"
|
58
|
+
elsif @public_key.nil?
|
59
|
+
raise Cryptic::InvalidKey, "Invalid public key: #{public_key}"
|
60
|
+
end
|
61
|
+
elsif e.message.eql? 'Neither PUB key nor PRIV key:: nested asn1 error'
|
62
|
+
raise Cryptic::IncorrectPassphrase, "Unable to open private key:
|
63
|
+
'#{private_key}'. was the passphrase valid?"
|
64
|
+
else
|
65
|
+
raise e
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
17
69
|
# Creates a keypair to be saved with #save
|
18
70
|
#
|
71
|
+
# @note The passphrase isn't saved
|
72
|
+
# @param [String] passphrase the passphrase to give the private key
|
19
73
|
# @param [Fixnum] size the amount of bits to use in your key
|
20
74
|
# @return [Keypair] an object representing a private/public keypair
|
21
|
-
def
|
22
|
-
|
23
|
-
|
75
|
+
def self.generate(passphrase = nil, size = 2048)
|
76
|
+
# OPTIMIZE: There are so many hammers in here it looks like we're playing
|
77
|
+
# Whack-a-mole
|
78
|
+
# TODO: Find a better way to handle retries
|
24
79
|
attempts ||= 0
|
25
80
|
attempts += 1
|
26
81
|
|
27
82
|
rsa_key = OpenSSL::PKey::RSA.new(size)
|
28
|
-
cipher
|
83
|
+
cipher ||= OpenSSL::Cipher::AES256.new(:CBC)
|
29
84
|
|
30
|
-
|
31
|
-
@public_key = rsa_key.public_key.to_pem
|
85
|
+
new(rsa_key.to_pem(cipher, passphrase), rsa_key.public_key.to_pem)
|
32
86
|
rescue OpenSSL::PKey::RSAError => e
|
33
87
|
if e.message =~ /^read key$/
|
34
88
|
retry unless attempts > 1
|
@@ -41,9 +95,10 @@ module Cryptic
|
|
41
95
|
#
|
42
96
|
# @param [String] path the path to save the keypair into
|
43
97
|
# @todo Document what save may raise
|
98
|
+
# @todo Update this method
|
44
99
|
# @return [String] returns the path files were saved to
|
45
100
|
def save(path = '.')
|
46
|
-
if @private_key.
|
101
|
+
if @private_key.to_pem.eql?('') || @public_key.to_pem.eql?('')
|
47
102
|
raise Cryptic::KeyGenerationFailure, "The keypair was never successfully generated"
|
48
103
|
end
|
49
104
|
|
@@ -57,7 +112,6 @@ module Cryptic
|
|
57
112
|
file.write @public_key
|
58
113
|
end
|
59
114
|
|
60
|
-
@saved = true
|
61
115
|
path
|
62
116
|
end
|
63
117
|
end
|
data/lib/cryptic/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Cryptic [![Build Status](https://secure.travis-ci.org/ipwnstuff/cryptic.png)](http://travis-ci.org/ipwnstuff/cryptic) [![Dependency Status](https://gemnasium.com/ipwnstuff/cryptic.png)](https://gemnasium.com/ipwnstuff/cryptic)
|
2
|
+
A Ruby gem for public key encryption, private key decryption, and generating key pairs.
|
3
|
+
|
4
|
+
## Documentation
|
5
|
+
http://www.rubydoc.info/github/ipwnstuff/cryptic
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Just run: `gem install cryptic` or add `gem 'cryptic'` to your Gemfile.
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
### Command line
|
12
|
+
|
13
|
+
```
|
14
|
+
[ecarey @ cryptic]$ cryptic
|
15
|
+
Commands:
|
16
|
+
cryptic decrypt [PRIVATE_KEY] [ENCRYPTED_FILE] [OPTIONS] # Decrypt a file with a private key
|
17
|
+
cryptic encrypt [PUBLIC_KEY] [TEXT_FILE] [OPTIONS] # Encrypt a file with a public key
|
18
|
+
cryptic generate [OPTIONS] # Generate a private/public keypair
|
19
|
+
cryptic help [COMMAND] # Describe available commands or one specific command
|
20
|
+
```
|
21
|
+
|
22
|
+
### Ruby
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'cryptic'
|
26
|
+
|
27
|
+
# Load a keypair to use:
|
28
|
+
keypair = Cryptic::Keypair.new('cryptic_private.pem', public_key: 'cryptic_public.pem')
|
29
|
+
|
30
|
+
# Obtain your public/private keys from the `Cryptic::Keypair` object:
|
31
|
+
private_key = keypair.private_key
|
32
|
+
public_key = keypair.public_key
|
33
|
+
|
34
|
+
# Encrypt a file:
|
35
|
+
data = File.read('foo.txt')
|
36
|
+
encrypted = Cryptic::EncryptedData.new(data, public_key, :base64)
|
37
|
+
|
38
|
+
# Returns an encrypted string you can save off to a file:
|
39
|
+
encrypted.data
|
40
|
+
|
41
|
+
# To return the data call decrypt on the encrypted data object w/ the private key and passphrase:
|
42
|
+
decrypted = encrypted.decrypt(private_key, 'P4$SpHr4z3', :base64)
|
43
|
+
```
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b feature/my-awesome-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin feature/my-awesome-feature`)
|
50
|
+
5. Create new Pull Request
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Cryptic [![Estado de Creación](https://secure.travis-ci.org/ipwnstuff/cryptic.png)](http://travis-ci.org/ipwnstuff/cryptic) [![Estado de Dependencia](https://gemnasium.com/ipwnstuff/cryptic.png)](https://gemnasium.com/ipwnstuff/cryptic)
|
2
|
+
Una Ruby gem para cifrar datos con su clave pública, descifrarlos con su clave privada, y generar nuevas claves.
|
3
|
+
|
4
|
+
## Documentación
|
5
|
+
Ahorita no hay ninguna documentación española.
|
6
|
+
En Inglès: http://www.rubydoc.info/github/ipwnstuff/cryptic
|
7
|
+
|
8
|
+
## Instalación
|
9
|
+
Sólo corra `gem install cryptic` o añada `gem 'cryptic'` a su `Gemfile`.
|
10
|
+
También se puede descargar desde el código fuente.
|
11
|
+
|
12
|
+
## Uso
|
13
|
+
### Línea de Comandos
|
14
|
+
|
15
|
+
```
|
16
|
+
[ecarey @ cryptic]$ cryptic
|
17
|
+
Commands:
|
18
|
+
cryptic decrypt [CLAVE_PRIVADA] [FICHERO_CIFRADO] [OPCIONES] # Descifrar una fichero con una clave privada
|
19
|
+
cryptic encrypt [CLAVE_PUBLICO] [FICHERO_TEXTO] [OPTIONS] # Cifrar una fichero con una clave pública
|
20
|
+
cryptic generate [OPTIONS] # Generar nuevas claves
|
21
|
+
cryptic help [COMMAND] # Describe available commands or one specific command
|
22
|
+
```
|
23
|
+
|
24
|
+
### Ruby
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'cryptic'
|
28
|
+
|
29
|
+
# Para cargar las claves existantes:
|
30
|
+
claves = Cryptic::Keypair.new('cryptic_private.pem', public_key: 'cryptic_public.pem')
|
31
|
+
|
32
|
+
# Obtener las claves desde el objeto `Cryptic::Keypair`:
|
33
|
+
clave_privada = claves.private_key
|
34
|
+
clave_publica = claves.public_key
|
35
|
+
|
36
|
+
# Cifrar un fichero:
|
37
|
+
datos = File.read('foo.txt')
|
38
|
+
cifrado = Cryptic::EncryptedData.new(datos, clave_publica, :base64)
|
39
|
+
|
40
|
+
# Retornar los datos cifrados:
|
41
|
+
cifrado.data
|
42
|
+
|
43
|
+
# Descifrarlos con su clave privada y su contraseña:
|
44
|
+
descifrado = cifrado.decrypt(clave_privada, 'P4$SpHr4z3', :base64)
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contribuyendo
|
48
|
+
1. Bifurcarlo
|
49
|
+
2. Crear un rama de la característica en Inglés (`git checkout -b feature/my-awesome-feature`)
|
50
|
+
3. Comfirmar su cambios con un mensaje Inglés (`git commit -am 'Add some feature'`)
|
51
|
+
4. Empujar a su rama (`git push origin feature/my-awesome-feature`)
|
52
|
+
5. Crear un nuevo Pull Request
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'cryptic/keypair'
|
2
|
+
|
3
|
+
describe Cryptic::Keypair do
|
4
|
+
let :private_keys do
|
5
|
+
keys = [
|
6
|
+
'./cryptic_private.pem',
|
7
|
+
File.read('./cryptic_private.pem')
|
8
|
+
]
|
9
|
+
|
10
|
+
# Repeat the keys for zipping
|
11
|
+
keys *= 2
|
12
|
+
end
|
13
|
+
|
14
|
+
let :public_keys do
|
15
|
+
keys = [
|
16
|
+
'./cryptic_public.pem',
|
17
|
+
File.read('./cryptic_public.pem')
|
18
|
+
]
|
19
|
+
|
20
|
+
# Repeat the keys in opposing order for zipping
|
21
|
+
keys += keys.reverse
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should be able to create a keypair from a private key' do
|
25
|
+
private_keys.uniq.each do |private_key|
|
26
|
+
expect {
|
27
|
+
Cryptic::Keypair.new(
|
28
|
+
private_key,
|
29
|
+
passphrase: 'P4$SpHr4z3'
|
30
|
+
)
|
31
|
+
}.to_not raise_error
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should be able to create a keypair from a private key and a public key' do
|
36
|
+
private_keys.zip(public_keys).each do |private_key, public_key|
|
37
|
+
expect {
|
38
|
+
Cryptic::Keypair.new(
|
39
|
+
private_key,
|
40
|
+
passphrase: 'P4$SpHr4z3',
|
41
|
+
public_key: public_key
|
42
|
+
)
|
43
|
+
}.to_not raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# TODO: Add custom error classes below once implemented
|
48
|
+
|
49
|
+
it 'should not be able to create a keypair with an empty private key' do
|
50
|
+
expect { Cryptic::Keypair.new('') }.to raise_error
|
51
|
+
expect { Cryptic::Keypair.new(nil) }.to raise_error
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should not be able to create a keypair with an invalid private key' do
|
55
|
+
public_keys.uniq.each do |public_key|
|
56
|
+
expect {
|
57
|
+
Cryptic::Keypair.new(
|
58
|
+
public_key,
|
59
|
+
passphrase: 'P4$SpHr4z3'
|
60
|
+
)
|
61
|
+
}.to raise_error
|
62
|
+
|
63
|
+
expect { Cryptic::Keypair.new(public_key) }.to raise_error
|
64
|
+
end
|
65
|
+
|
66
|
+
expect { Cryptic::Keypair.new('invalid') }.to raise_error
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should not be able to create a keypair with an invalid passphrase' do
|
70
|
+
private_keys.uniq.each do |private_key|
|
71
|
+
expect {
|
72
|
+
Cryptic::Keypair.new(
|
73
|
+
private_key,
|
74
|
+
passphrase: 'BadPassphrase'
|
75
|
+
)
|
76
|
+
}.to raise_error
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.beta.
|
4
|
+
version: 1.0.0.beta.7
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
@@ -139,19 +139,25 @@ files:
|
|
139
139
|
- Thorfile
|
140
140
|
- bin/cryptic
|
141
141
|
- cryptic.gemspec
|
142
|
+
- cryptic_private.pem
|
143
|
+
- cryptic_public.pem
|
142
144
|
- lib/cryptic.rb
|
143
145
|
- lib/cryptic/encrypted_data.rb
|
144
146
|
- lib/cryptic/exceptions.rb
|
145
147
|
- lib/cryptic/exceptions/decryption_error.rb
|
146
148
|
- lib/cryptic/exceptions/encryption_error.rb
|
149
|
+
- lib/cryptic/exceptions/incorrect_passphrase.rb
|
147
150
|
- lib/cryptic/exceptions/invalid_data.rb
|
151
|
+
- lib/cryptic/exceptions/invalid_key.rb
|
148
152
|
- lib/cryptic/exceptions/key_generation_failure.rb
|
149
153
|
- lib/cryptic/exceptions/key_mismatch.rb
|
150
154
|
- lib/cryptic/exceptions/key_not_found.rb
|
151
155
|
- lib/cryptic/exceptions/unsupported_encoding.rb
|
152
156
|
- lib/cryptic/keypair.rb
|
153
157
|
- lib/cryptic/version.rb
|
154
|
-
-
|
158
|
+
- locales/files/README.en.md
|
159
|
+
- locales/files/README.es.md
|
160
|
+
- spec/keypair_spec.rb
|
155
161
|
homepage: https://github.com/ipwnstuff/cryptic
|
156
162
|
licenses:
|
157
163
|
- MIT
|
@@ -167,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
173
|
version: '0'
|
168
174
|
segments:
|
169
175
|
- 0
|
170
|
-
hash: -
|
176
|
+
hash: -1776955629962300703
|
171
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
178
|
none: false
|
173
179
|
requirements:
|
@@ -182,5 +188,5 @@ specification_version: 3
|
|
182
188
|
summary: A quick way to encrypt data using public keys. Only people with the private
|
183
189
|
key can decrypt said data.
|
184
190
|
test_files:
|
185
|
-
- spec/
|
191
|
+
- spec/keypair_spec.rb
|
186
192
|
has_rdoc:
|
data/spec/default_spec.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# TODO: Implement tests
|