gpgc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ .project
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ enc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gpgcrypt.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TheNotary
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.
@@ -0,0 +1,67 @@
1
+ # Gpgcrypt
2
+
3
+ This gem is designed to allow you to manually encrypt/ decrypt RSA encoded messages using GnuPG.
4
+
5
+ ## Installation
6
+
7
+ Install the gem:
8
+
9
+ $ gem install gpgcrypt
10
+
11
+ ## Usage Template
12
+ Encrypting:
13
+
14
+ $ gpgcrypt message public_key
15
+
16
+ Decrypting:
17
+
18
+ $ gpgcrypt encrypted_message private_key
19
+
20
+ ## Usage
21
+
22
+ Have your partner generate a public/private key pair (You may have already done this).
23
+
24
+ $ ssh-keygen -t rsa
25
+
26
+ Obtain a copy of your partner's public key.
27
+
28
+ And then use gpgcrypt to encrypt a message using your partner's public key:
29
+
30
+ $ gpgcrypt message.txt public_key_of_recipient_rsa.pub > encrypted_message.txt
31
+
32
+ Or have your partner decrypt a message of yours using your own private key:
33
+
34
+ $ gpgcrypt encrypted_message.txt your_private_key_rsa > message.txt
35
+
36
+
37
+ ## Alternate Usage
38
+
39
+ You can alternatively specify a URL to public keys or messages
40
+
41
+ Encrypting:
42
+
43
+ $ gpgcrypt message.txt github.com/TheNotary/pgp/raw
44
+ Your message has been pastebin'd to http://pastebin.com/lkajds;lkfjsdaf
45
+
46
+ Decrypting:
47
+
48
+ $ gpgcrypt http://pastebin.com/lkajds;lkfjsdaf ~/.ssh/id_rsa
49
+
50
+
51
+
52
+ Later, you will be able to add other people's public keys to your ~/.gpgc folder. Then you will be able to set their key as the default key.
53
+
54
+ $ gpgc --save-key pastebin.com/raw/;laksjdflkjdf joe
55
+ $ gpgc --converse-with ~/.gpgc/joe
56
+ $ gpgc "Hey, let me know when you've made the finishing touches."
57
+
58
+
59
+
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
@@ -0,0 +1,25 @@
1
+ require 'bundler'
2
+ include Rake::DSL
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require "rspec/core/rake_task" # RSpec 2.0
6
+
7
+ RSpec::Core::RakeTask.new(:unit) do |spec|
8
+ #spec.pattern = 'spec/*/*_spec.rb'
9
+ spec.pattern = 'spec/unit/*_spec.rb'
10
+ spec.rspec_opts = ['--backtrace']
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:all) do |spec|
14
+ spec.pattern = 'spec/*/*_spec.rb'
15
+ #spec.rspec_opts = ['--debug']
16
+ end
17
+
18
+ # this is for running tests that you've marked current... eg: it 'should work', :current => true do
19
+ RSpec::Core::RakeTask.new(:current) do |spec|
20
+ spec.pattern = 'spec/*/*_spec.rb'
21
+ spec.rspec_opts = ['--tag current']
22
+ end
23
+
24
+
25
+ task :default => :all
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require 'thor'
4
+ require 'pry'
5
+ require 'gpgcrypt'
6
+
7
+
8
+
9
+ if ARGV[0].nil? or ARGV[0].downcase.chomp.strip =~ /^(\-|\-\-)help$/ or ARGV[0] == "" # regex captures help, -help, or --help.
10
+ puts GpgCrypt.help
11
+ elsif ARGV[0].downcase.chomp.strip == "export"
12
+ # TODO
13
+ elseif ARGV[0].downcase.chomp.strip == "--save-key"
14
+ puts "The feature hasn't yet been implemented."
15
+ elseif ARGV[0].downcase.chomp.strip == "--converse-with"
16
+ puts "The feature hasn't yet been implemented."
17
+ elsif ARGV.count != 2
18
+ puts "You need to pass in two parameters, a path to a msg and a path to an RSA key."
19
+ else
20
+ puts GpgCrypt.encrypt_or_decrypt(ARGV[0], ARGV[1])
21
+ end
22
+
23
+
24
+
25
+
26
+
27
+
28
+ =begin
29
+ class GpgCryptRunner < Thor
30
+ default_task :help
31
+
32
+ desc "help", "Explains the gem's usage on the command line."
33
+ def help
34
+ binding.pry
35
+ puts $my_args
36
+ puts GpgCrypt.help
37
+ end
38
+
39
+ #desc "encrypt/ Decrypt", "either decrypts or encrypts something based on whether u supply a pub/priv key."
40
+ #def *args
41
+
42
+ end
43
+
44
+ GpgCryptRunner.start
45
+
46
+ =end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gpgcrypt/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "gpgc"
8
+ gem.version = GpgCrypt::VERSION
9
+ gem.authors = ["TheNotary"]
10
+ gem.email = ["no@mail.plz"]
11
+ gem.description = %q{GpgCrypt is a gem that helps you encrypt messages.}
12
+ gem.summary = %q{This gem is designed to allow you to manually encrypt/ decrypt RSA encoded messages using GnuPG.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "gibberish"
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "pry"
24
+ end
@@ -0,0 +1,138 @@
1
+ require 'gibberish'
2
+ require 'pry'
3
+ require 'uri'
4
+ require 'open-uri'
5
+
6
+ require "gpgcrypt/version"
7
+
8
+ module GpgCrypt
9
+
10
+ def self.encrypt_or_decrypt(*args)
11
+ key_data = File.read(args[1]) #if File.exists
12
+ key_type = get_key_type?(key_data) # args[1] is either a public key or a private key...
13
+
14
+ # convert_key_to_pem_format
15
+ if key_type == :open_ssh
16
+ key_data = convert_openssh_public_key_to_openssl(key_data)
17
+ key_type = get_key_type?(key_data) # if this fails, we should set key_type to :incompatible
18
+ end
19
+
20
+ # get_message_data decide where to read a file as the message, or use the first param
21
+ if File.exist? args[0]
22
+ message_data = File.read(args[0])
23
+ else
24
+ message_data = args[0]
25
+ end
26
+
27
+ case key_type
28
+ when :public
29
+ encrypt(message_data, key_data)
30
+ when :private
31
+ decrypt(message_data, key_data)
32
+ else # :incompatible or even possibly :open_ssh if something odd happens
33
+ puts "The key entered was niether a public nor private key. Check that you passed in a proper path to a key as the second parameter."
34
+ end
35
+ end
36
+
37
+ # @param [string] message
38
+ #
39
+ # @param [string] public_key
40
+ #
41
+ # @return [string] encrypted message
42
+ #
43
+ def self.encrypt(message, public_key)
44
+ message_string = message
45
+ public_key_string = public_key
46
+
47
+ # encrypt the message
48
+ cipher = Gibberish::RSA.new(public_key_string)
49
+ encrypted_message = cipher.encrypt(message_string)
50
+ end
51
+
52
+ # @param [string] encrypted message
53
+ #
54
+ # @param [string] public key in PEM format
55
+ #
56
+ # @return [string] decrypted message
57
+ #
58
+ def self.decrypt(encrypted_message, private_key)
59
+ message_string = encrypted_message
60
+ private_key_string = private_key
61
+
62
+ # decrypt the message
63
+ dec_cipher = Gibberish::RSA.new(private_key_string)
64
+ decrypted_message = dec_cipher.decrypt(message_string)
65
+ end
66
+
67
+ # This command let's you read your private key and generate from that
68
+ # a suitable public key which will be posted to pastebin.
69
+ def self.export_public_key(private_key)
70
+ raise "stub: not yet implemented"
71
+ end
72
+
73
+ def self.help
74
+ hlp = "gpgcrypt allows you to 'manually' encrypt and decrypt messages over the command line.\n\n"
75
+ hlp += "To encrypt a message: \n Supply a path to a file containing a message and an openSSL style public key. \n\n"
76
+ hlp += "To decrypt a message: \n Supply a path to a file containing an encrypted message and a private key.\n\n"
77
+ hlp += "Soon you'll be able to export a public key from your private key and automatically pastebin it so others can message you.\n\n"
78
+ hlp += "As an added feature, someday you will be able to specify pastebin links to encrypted messages and public keys"
79
+ hlp
80
+ end
81
+
82
+
83
+ # checks if a string is a path to a file or a URL
84
+ # Returns a string of the file or URL page contents
85
+ def self.path_to_content(string)
86
+ string_is_a_file = File.exists? string
87
+ string_is_a_uri = string =~ URI::regexp
88
+ if string_is_a_file
89
+ File.read(string)
90
+ elsif string_is_a_uri
91
+ URI.parse(string).read
92
+ end
93
+ end
94
+
95
+ def scan_if_encrypted_message(string)
96
+ return true if is_string_private_key?
97
+ false
98
+ end
99
+
100
+ def self.convert_openssh_public_key_to_openssl(public_key_string, check_key_type = true)
101
+ return public_key_string if get_key_type?(public_key_string) == :public
102
+
103
+ # return public_key_string if true
104
+ temp_file_path = '/tmp/gpgcrypt_pubtest'
105
+ File.open(temp_file_path, "w+") do |f|
106
+ f.puts public_key_string
107
+ end
108
+ File.chmod(0600, temp_file_path)
109
+
110
+ # binding.pry
111
+ #openssl_key = `openssl rsa -in #{temp_file_path} -out pub.der -outform pem -pubout`
112
+ openssl_key = `ssh-keygen -f #{temp_file_path} -e -m pem`
113
+ File.delete(temp_file_path)
114
+ return openssl_key
115
+ end
116
+
117
+
118
+ def self.get_key_type?(string)
119
+ valid_private_key = :incompatible
120
+
121
+ return :open_ssh if string =~ /^ssh-rsa/
122
+
123
+ begin
124
+ k = OpenSSL::PKey::RSA.new(string)
125
+ if k.private?
126
+ valid_private_key = :private
127
+ elsif k.public?
128
+ valid_private_key = :public
129
+ else
130
+ valid_private_key = :incompatible
131
+ end
132
+ rescue
133
+ valid_private_key = :incompatible
134
+ end
135
+ valid_private_key
136
+ end
137
+
138
+ end
@@ -0,0 +1,3 @@
1
+ module GpgCrypt
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ These words are the contents of spec/dummy/msg
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEogIBAAKCAQEAoxi2V0bSKqAqUtoQHxWkOPnErCS541r6/MOSHmKOd6VSNHoB
3
+ bnasZRQSDUTbffB6C++DbmBCOHmvzYORD0ZWYgyMcgbYJD48Z2fe0nm+WMYN5u8D
4
+ PnTPvf8b/rJBxGF0dsaoFAWlB81tTnKFCxAbCSgfmQt+Vd4qupGZ5gGu9uoKlaPj
5
+ mYuAIxIjUMcu3dov7PQ+PZIvdkM0fiz8YIl8zo+iWWyI2s6/XLoZJ4bYs2YJHZDf
6
+ 6biUsZhs8xqh/F6qlcRt3Ta25KMa0TB9zE3HHmqA/EJHFubWFRCrQqpboB0+nwCb
7
+ mZUlhaxA79FRvYtORvFAoncoFD4tq3rGXcUQQwIDAQABAoIBAEiF9p78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uZlSWFrEDv0VG9i05G8UCidygUPi2resZdxRBD
@@ -0,0 +1 @@
1
+ require 'gpgcrypt'
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+
4
+
5
+ describe GpgCrypt do
6
+
7
+ before :each do
8
+ @ssh_pub_path = 'spec/dummy/ssh_pub_key'
9
+ @pub_path = "spec/dummy/pub_key"
10
+ @priv_path = "spec/dummy/priv_key"
11
+ @msg_path = "spec/dummy/msg"
12
+
13
+ @pub_key = "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAoxi2V0bSKqAqUtoQHxWkOPnErCS541r6/MOSHmKOd6VSNHoBbnas\nZRQSDUTbffB6C++DbmBCOHmvzYORD0ZWYgyMcgbYJD48Z2fe0nm+WMYN5u8DPnTP\nvf8b/rJBxGF0dsaoFAWlB81tTnKFCxAbCSgfmQt+Vd4qupGZ5gGu9uoKlaPjmYuA\nIxIjUMcu3dov7PQ+PZIvdkM0fiz8YIl8zo+iWWyI2s6/XLoZJ4bYs2YJHZDf6biU\nsZhs8xqh/F6qlcRt3Ta25KMa0TB9zE3HHmqA/EJHFubWFRCrQqpboB0+nwCbmZUl\nhaxA79FRvYtORvFAoncoFD4tq3rGXcUQQwIDAQAB\n-----END RSA PUBLIC KEY-----\n"
14
+ @priv_key = "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAoxi2V0bSKqAqUtoQHxWkOPnErCS541r6/MOSHmKOd6VSNHoB\nbnasZRQSDUTbffB6C++DbmBCOHmvzYORD0ZWYgyMcgbYJD48Z2fe0nm+WMYN5u8D\nPnTPvf8b/rJBxGF0dsaoFAWlB81tTnKFCxAbCSgfmQt+Vd4qupGZ5gGu9uoKlaPj\nmYuAIxIjUMcu3dov7PQ+PZIvdkM0fiz8YIl8zo+iWWyI2s6/XLoZJ4bYs2YJHZDf\n6biUsZhs8xqh/F6qlcRt3Ta25KMa0TB9zE3HHmqA/EJHFubWFRCrQqpboB0+nwCb\nmZUlhaxA79FRv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i59qclR30evucRX8eYT\nSMrVAoGAISImqYF376/pz/9TNEl5P8yOlIOG4grwzuykoBpFh98UCCiW/wzH5zCt\nMiy9hFH6Lgj9HGtsx/TvclgMBQtktBn5MrNarC8zWCAfIEaNQAkb6GrYXxrO2jnI\nOW7+BgxGQGFwtn+2TrJQOsgwFTZx1AmG53m3jhiO2HC2kd1VqgM=\n-----END RSA PRIVATE KEY-----\n"
15
+ @ssh_pub_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjGLZXRtIqoCpS2hAfFaQ4+cSsJLnjWvr8w5IeYo53pVI0egFudqxlFBINRNt98HoL74NuYEI4ea/Ng5EPRlZiDIxyBtgkPjxnZ97Seb5Yxg3m7wM+dM+9/xv+skHEYXR2xqgUBaUHzW1OcoULEBsJKB+ZC35V3iq6kZnmAa726gqVo+OZi4AjEiNQxy7d2i/s9D49ki92QzR+LPxgiXzOj6JZbIjazr9cuhknhtizZgkdkN/puJSxmGzzGqH8XqqVxG3dNrbkoxrRMH3MTcceaoD8QkcW5tYVEKtCqlugHT6fAJuZlSWFrEDv0VG9i05G8UCidygUPi2resZdxRBD"
16
+
17
+ @unencrypted_message = 'hello world!'
18
+ end
19
+
20
+ it "Should encrypt and decrypt a message based on a private key string" do
21
+ enc = GpgCrypt.encrypt(@unencrypted_message, @pub_key)
22
+ enc.should_not eq @unencrypted_message
23
+ msg = GpgCrypt.decrypt(enc, @priv_key)
24
+ msg.should eq @unencrypted_message
25
+ end
26
+
27
+ it "Should encrypt the contents of a file name passed in" do
28
+ enc = GpgCrypt.encrypt_or_decrypt(@msg_path, @pub_path)
29
+ GpgCrypt.encrypt_or_decrypt(enc, @priv_path).should eq File.read(@msg_path)
30
+ end
31
+
32
+ it "Should encrypt the first parameter passed in if it's not a file" do
33
+ enc = GpgCrypt.encrypt_or_decrypt(@unencrypted_message, @pub_path)
34
+ GpgCrypt.encrypt_or_decrypt(enc, @priv_path).should eq @unencrypted_message
35
+ end
36
+
37
+ # http://unix.stackexchange.com/questions/26924/how-do-i-convert-a-ssh-keygen-public-key-into-a-format-that-openssl-pem-read-bio
38
+ # Usecase:
39
+ # You just generated a key pair via ssh-keygen.
40
+ #
41
+ # You manually pastebin your public key so your partner can communicate with you.
42
+ #
43
+ # Your partner then wants to quickly encrypt a message by
44
+ # $ gpgcrypt "hey, tell me if you can decrypt this" ~/.ssh/id_rsa.pub
45
+ #
46
+ # This function will automatically convert the openSSH format into PEM
47
+ #
48
+ it "should convert ssh keys into openssl keys", :current => true do
49
+ key = GpgCrypt.convert_openssh_public_key_to_openssl(@ssh_pub_key)
50
+ key.should eq @pub_key
51
+ end
52
+
53
+ it "Should encrypt the file even if it's an ssh public key file that's supplied" do
54
+ enc = GpgCrypt.encrypt_or_decrypt(@msg_path, @ssh_pub_path)
55
+ GpgCrypt.encrypt_or_decrypt(enc, @priv_path).should eq File.read(@msg_path)
56
+ end
57
+
58
+ it "should be able to determine whether it should encrypt or decrypt something" do
59
+ GpgCrypt.get_key_type?(@pub_key).should be :public
60
+ GpgCrypt.get_key_type?(@priv_key).should be :private
61
+ GpgCrypt.get_key_type?("@priv_key").should be :incompatible
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gpgc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TheNotary
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gibberish
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: GpgCrypt is a gem that helps you encrypt messages.
79
+ email:
80
+ - no@mail.plz
81
+ executables:
82
+ - gpgc
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/gpgc
92
+ - gpgc.gemspec
93
+ - lib/gpgcrypt.rb
94
+ - lib/gpgcrypt/version.rb
95
+ - spec/dummy/enc
96
+ - spec/dummy/msg
97
+ - spec/dummy/priv_key
98
+ - spec/dummy/pub_key
99
+ - spec/dummy/ssh_pub_key
100
+ - spec/spec_helper.rb
101
+ - spec/unit/gpgcrypt_spec.rb
102
+ homepage: ''
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.23
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: This gem is designed to allow you to manually encrypt/ decrypt RSA encoded
126
+ messages using GnuPG.
127
+ test_files:
128
+ - spec/dummy/enc
129
+ - spec/dummy/msg
130
+ - spec/dummy/priv_key
131
+ - spec/dummy/pub_key
132
+ - spec/dummy/ssh_pub_key
133
+ - spec/spec_helper.rb
134
+ - spec/unit/gpgcrypt_spec.rb
135
+ has_rdoc: