crypto64 1.0.0

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.
Files changed (5) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Rakefile +35 -0
  3. data/VERSION +1 -0
  4. data/lib/crypto64.rb +46 -0
  5. metadata +65 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Bart Teeuwisse
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = 'crypto64'
8
+ gem.summary = 'Encrypt and decrypt text of arbitrary length using RSA cyphers'
9
+ gem.authors = '[Bart Teeuwisse]'
10
+ gem.email = '<bart.teeuwisse@thecodemill.biz>'
11
+ gem.description = <<-END
12
+ Encrypt and decrypt text of arbitrary length using RSA cyphers.
13
+ Extends the RSA class from the openssl library.
14
+ END
15
+ gem.homepage = 'http://github.com/bartt/crypto64'
16
+ readmes = FileList.new('*') { |list| list.exclude(/[a-z]/) }.to_a
17
+ gem.files = FileList['lib/**/*', 'bin/*', 'test/**/*', 'Rakefile'].to_a + readmes
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ task :spec => :check_dependencies
25
+
26
+ task :default => :spec
27
+
28
+ begin
29
+ require 'yard'
30
+ YARD::Rake::YardocTask.new
31
+ rescue LoadError
32
+ task :yardoc do
33
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
34
+ end
35
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,46 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ include OpenSSL
4
+ include PKey
5
+
6
+ class RSA
7
+
8
+ # Read the length of the private key.
9
+ def size
10
+ /(\d+ bit)/.match(self.to_text)[0].split(' ')[0].to_i
11
+ end
12
+
13
+ # Calculate the block size when encrypting.
14
+ def encrypt_block_size
15
+ (size/8)-12
16
+ end
17
+
18
+ # Calculate the block size when decrypting.
19
+ def decrypt_block_size
20
+ (size/8)-1
21
+ end
22
+
23
+ # Encrypt and base64 encode data of arbitrary length.
24
+ def encrypt64(str)
25
+ enc = ''
26
+ while str.length > self.encrypt_block_size
27
+ enc += self.public_encrypt(str[0..self.encrypt_block_size])
28
+ str = str[self.encrypt_block_size+1..-1] if str.length > self.encrypt_block_size
29
+ end
30
+ if str.length != 0 then
31
+ enc += self.public_encrypt(str[0..self.encrypt_block_size])
32
+ end
33
+ Base64.encode64(enc)
34
+ end
35
+
36
+ # Decrypt and base64 decode data of arbitrary length.
37
+ def decrypt64(str)
38
+ dec = ''
39
+ str = Base64.decode64(str)
40
+ while str.length != 0
41
+ dec += self.private_decrypt(str[0..self.decrypt_block_size])
42
+ str = str[self.decrypt_block_size+1..-1] if str.length > self.decrypt_block_size
43
+ end
44
+ dec
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crypto64
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - "[Bart Teeuwisse]"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-21 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " Encrypt and decrypt text of arbitrary length using RSA cyphers.\n Extends the RSA class from the openssl library.\n"
22
+ email: <bart.teeuwisse@thecodemill.biz>
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - MIT-LICENSE
31
+ - Rakefile
32
+ - VERSION
33
+ - lib/crypto64.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/bartt/crypto64
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.6
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Encrypt and decrypt text of arbitrary length using RSA cyphers
64
+ test_files: []
65
+