block64 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +16 -0
- data/LICENSE +21 -0
- data/README.rdoc +19 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/block64.gemspec +51 -0
- data/lib/block64.rb +76 -0
- metadata +103 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.5.1"
|
11
|
+
end
|
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2007 Bart Teeuwisse
|
2
|
+
Copyright (c) 2010 Martin Kozák
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= block64
|
2
|
+
|
3
|
+
Please, see source code.
|
4
|
+
|
5
|
+
== Contributing to block64
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2007 Bart Teeuwisse and (c) 2010 Martin Kozák. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "block64"
|
17
|
+
gem.homepage = "http://github.com/martinkozak/block64"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = 'Encrypt and decrypt text of arbitrary length using RSA cyphers. Fixed and much faster fork of "crypto64" gem.'
|
20
|
+
#gem.description = %Q{TODO: longer description of your gem}
|
21
|
+
gem.email = "martinkozak@martinkozak.net"
|
22
|
+
gem.authors = ["Martin Kozák"]
|
23
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
24
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
25
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
26
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rake/rdoctask'
|
31
|
+
Rake::RDocTask.new do |rdoc|
|
32
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
33
|
+
|
34
|
+
rdoc.rdoc_dir = 'rdoc'
|
35
|
+
rdoc.title = "block64 #{version}"
|
36
|
+
rdoc.rdoc_files.include('README*')
|
37
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/block64.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{block64}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Martin Kozák"]
|
12
|
+
s.date = %q{2010-11-30}
|
13
|
+
s.email = %q{martinkozak@martinkozak.net}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"block64.gemspec",
|
27
|
+
"lib/block64.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/martinkozak/block64}
|
30
|
+
s.licenses = ["MIT"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.7}
|
33
|
+
s.summary = %q{Encrypt and decrypt text of arbitrary length using RSA cyphers. Fixed and much faster fork of "crypto64" gem.}
|
34
|
+
|
35
|
+
if s.respond_to? :specification_version then
|
36
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
41
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
44
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
45
|
+
end
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/lib/block64.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
include OpenSSL
|
5
|
+
include PKey
|
6
|
+
|
7
|
+
class RSA
|
8
|
+
|
9
|
+
BIT_MATCHER = /(\d+) bit/
|
10
|
+
|
11
|
+
@size
|
12
|
+
@encrypt_block_size
|
13
|
+
@decrypt_block_size
|
14
|
+
|
15
|
+
# Read the length of the private key.
|
16
|
+
def size
|
17
|
+
if @size.nil?
|
18
|
+
@size = self.class::BIT_MATCHER.match(self.to_text)[1].to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
return @size
|
22
|
+
end
|
23
|
+
|
24
|
+
# Calculate the block size when encrypting.
|
25
|
+
def encrypt_block_size
|
26
|
+
if @encrypt_block_size.nil?
|
27
|
+
@encrypt_block_size = (self.size / 8) - 14
|
28
|
+
end
|
29
|
+
|
30
|
+
return @encrypt_block_size
|
31
|
+
end
|
32
|
+
|
33
|
+
# Calculate the block size when decrypting.
|
34
|
+
def decrypt_block_size
|
35
|
+
if @decrypt_block_size.nil?
|
36
|
+
@decrypt_block_size = (self.size / 8) - 1
|
37
|
+
end
|
38
|
+
|
39
|
+
return @decrypt_block_size
|
40
|
+
end
|
41
|
+
|
42
|
+
# Encrypt and base64 encode data of arbitrary length.
|
43
|
+
def encrypt64(str)
|
44
|
+
enc = ''
|
45
|
+
str = str.dup
|
46
|
+
encrypt_block_size = self.encrypt_block_size
|
47
|
+
|
48
|
+
while str.length > encrypt_block_size
|
49
|
+
enc << self.public_encrypt(str[0..encrypt_block_size])
|
50
|
+
str.replace(str[self.encrypt_block_size + 1..-1])
|
51
|
+
end
|
52
|
+
|
53
|
+
if str.length > 0
|
54
|
+
enc << self.public_encrypt(str[0..encrypt_block_size])
|
55
|
+
end
|
56
|
+
|
57
|
+
return Base64.encode64(enc)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Decrypt and base64 decode data of arbitrary length.
|
61
|
+
def decrypt64(str)
|
62
|
+
dec = ''
|
63
|
+
str = Base64.decode64(str)
|
64
|
+
decrypt_block_size = self.decrypt_block_size
|
65
|
+
|
66
|
+
while str.length > 0
|
67
|
+
dec << self.private_decrypt(str[0..decrypt_block_size])
|
68
|
+
if str.length > decrypt_block_size
|
69
|
+
str.replace(str[self.decrypt_block_size + 1..-1])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
return dec
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: block64
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Martin Koz\xC3\xA1k"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-30 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 1.0.0
|
32
|
+
type: :development
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jeweler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 5
|
45
|
+
- 1
|
46
|
+
version: 1.5.1
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
description:
|
51
|
+
email: martinkozak@martinkozak.net
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
files:
|
60
|
+
- .document
|
61
|
+
- Gemfile
|
62
|
+
- Gemfile.lock
|
63
|
+
- LICENSE
|
64
|
+
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- block64.gemspec
|
68
|
+
- lib/block64.rb
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://github.com/martinkozak/block64
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: -1459877424311062020
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.3.7
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Encrypt and decrypt text of arbitrary length using RSA cyphers. Fixed and much faster fork of "crypto64" gem.
|
102
|
+
test_files: []
|
103
|
+
|