ezcrypter 0.2
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.
- data/README +3 -0
- data/lib/ezcrypter.rb +11 -0
- data/lib/ezcrypter/default_worker.rb +37 -0
- data/lib/ezcrypter/keeper.rb +50 -0
- data/lib/ezcrypter/kernel.rb +27 -0
- data/lib/ezcrypter/string.rb +54 -0
- metadata +70 -0
data/README
ADDED
data/lib/ezcrypter.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module EzCrypter # :nodoc:
|
2
|
+
# The default worker is one that is used when no other worker is specified or the
|
3
|
+
# specified worker does not exist. It uses the EzCrypto library and get's
|
4
|
+
# its secret key from configatron.default_secret_key
|
5
|
+
class DefaultWorker
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
options = {:secret_key => String.randomize_full_ascii(40), :salt => "_eat_oreos_and_be_happy"}.merge(options)
|
9
|
+
@aes_key = EzCrypto::Key.with_password(options[:secret_key], options[:salt])
|
10
|
+
end
|
11
|
+
|
12
|
+
# Encrypts a string using the EzCrypto library and the secret key found in
|
13
|
+
# configatron.default_secret_key
|
14
|
+
def ez_encrypt(x)
|
15
|
+
@aes_key.encrypt(x)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Decrypts a string using the EzCrypto library and the secret key found in
|
19
|
+
# configatron.default_secret_key
|
20
|
+
def ez_decrypt(x)
|
21
|
+
@aes_key.decrypt(x)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Encrypts a string using the EzCrypto library and the secret key found in
|
25
|
+
# configatron.default_secret_key
|
26
|
+
def ez_encrypt64(x)
|
27
|
+
@aes_key.encrypt64(x)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Decrypts a string using the EzCrypto library and the secret key found in
|
31
|
+
# configatron.default_secret_key
|
32
|
+
def ez_decrypt64(x)
|
33
|
+
@aes_key.decrypt64(x)
|
34
|
+
end
|
35
|
+
|
36
|
+
end # DefaultWorker
|
37
|
+
end # Crypt
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module EzCrypter
|
2
|
+
# A singleton class that holds/manages all the workers for the system.
|
3
|
+
#
|
4
|
+
# A worker must be defined as EzCrypter::<name>Worker and must
|
5
|
+
# define an ez_encrypt(value) method and a ez_decrypt(value) method.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# class EzCrypter::ReverseWorker
|
9
|
+
# def ez_encrypt(x)
|
10
|
+
# x.reverse
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def ez_decrypt(x)
|
14
|
+
# x.reverse
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
class Keeper
|
18
|
+
include Singleton
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@crypt_workers_cache = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns a worker object to handle the encrytion/decryption.
|
25
|
+
# If the specified worker doesn't exist then EzCrypter::DefaultWorker
|
26
|
+
# is returned.
|
27
|
+
def worker(key = :default, options = {})
|
28
|
+
# Needs poor man's camelcase
|
29
|
+
if key.is_a?(Symbol)
|
30
|
+
key = key.to_s
|
31
|
+
key[0,1] = key[0,1].upcase
|
32
|
+
end
|
33
|
+
worker = @crypt_workers_cache[key.to_sym]
|
34
|
+
if worker.nil?
|
35
|
+
worker_klass = key + "Worker"
|
36
|
+
if EzCrypter.const_defined?(worker_klass)
|
37
|
+
worker = nil
|
38
|
+
worker = eval("worker = EzCrypter::#{worker_klass}.new(options)")
|
39
|
+
# puts "worker class inst #{worker.class.name}"
|
40
|
+
else
|
41
|
+
worker = EzCrypter::DefaultWorker.new(options)
|
42
|
+
# puts "worker class inst defaulted to #{worker.class.name}"
|
43
|
+
end
|
44
|
+
@crypt_workers_cache[key.to_sym] = worker
|
45
|
+
end
|
46
|
+
worker
|
47
|
+
end
|
48
|
+
|
49
|
+
end # Keeper
|
50
|
+
end # Crypt
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
# A helper method that calls Mack::Utils::Crypt::Keeper with the specified worker
|
4
|
+
# and calls the encrypt method on that worker.
|
5
|
+
def _ez_encrypt(value, worker = :default)
|
6
|
+
EzCrypter::Keeper.instance.worker(worker).ez_encrypt(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
# A helper method that calls Mack::Utils::Crypt::Keeper with the specified worker
|
10
|
+
# and calls the decrypt method on that worker.
|
11
|
+
def _ez_decrypt(value, worker = :default)
|
12
|
+
EzCrypter::Keeper.instance.worker(worker).ez_decrypt(value)
|
13
|
+
end
|
14
|
+
|
15
|
+
# A helper method that calls Mack::Utils::Crypt::Keeper with the specified worker
|
16
|
+
# and calls the encrypt method on that worker.
|
17
|
+
def _ez_encrypt64(value, worker = :default)
|
18
|
+
EzCrypter::Keeper.instance.worker(worker).ez_encrypt64(value)
|
19
|
+
end
|
20
|
+
|
21
|
+
# A helper method that calls Mack::Utils::Crypt::Keeper with the specified worker
|
22
|
+
# and calls the decrypt method on that worker.
|
23
|
+
def _ez_decrypt64(value, worker = :default)
|
24
|
+
EzCrypter::Keeper.instance.worker(worker).ez_decrypt64(value)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def self.randomize_full_ascii(length = 10)
|
4
|
+
unless defined?(String::RANDOM_STRING_SEED)
|
5
|
+
chars = Array.new(255,nil)
|
6
|
+
255.times do |char|
|
7
|
+
chars[char] = (char + 1).chr
|
8
|
+
end
|
9
|
+
String.const_set('RANDOM_STRING_SEED',chars)
|
10
|
+
end
|
11
|
+
chars = String::RANDOM_STRING_SEED
|
12
|
+
new_string = ""
|
13
|
+
rand_limit = String::RANDOM_STRING_SEED.size - 1
|
14
|
+
1.upto(length) { |i| new_string << chars[rand(rand_limit)] }
|
15
|
+
return new_string
|
16
|
+
end
|
17
|
+
|
18
|
+
# Maps to Kernel _ez_encrypt
|
19
|
+
#
|
20
|
+
# Examples:
|
21
|
+
# "Hello World".ez_encrypt
|
22
|
+
# "Hello World".ez_encrypt(:my_crypt)
|
23
|
+
def ez_encrypt(worker = :default)
|
24
|
+
_ez_encrypt(self, worker)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Maps to Kernel _ez_decrypt
|
28
|
+
#
|
29
|
+
# Examples:
|
30
|
+
# some_encrypted_string.ez_decrypt
|
31
|
+
# some_encrypted_string.ez_ecrypt(:my_crypt)
|
32
|
+
def ez_decrypt(worker = :default)
|
33
|
+
_ez_decrypt(self, worker)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Maps to Kernel _ez_encrypt64
|
37
|
+
#
|
38
|
+
# Examples:
|
39
|
+
# "Hello World".ez_encrypt
|
40
|
+
# "Hello World".ez_encrypt(:my_crypt)
|
41
|
+
def ez_encrypt64(worker = :default)
|
42
|
+
_ez_encrypt64(self, worker)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Maps to Kernel _ez_decrypt64
|
46
|
+
#
|
47
|
+
# Examples:
|
48
|
+
# some_encrypted_string.ez_decrypt
|
49
|
+
# some_encrypted_string.ez_ecrypt(:my_crypt)
|
50
|
+
def ez_decrypt64(worker = :default)
|
51
|
+
_ez_decrypt64(self, worker)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ezcrypter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tracy Flynn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-23 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ezcrypto
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.7"
|
24
|
+
version:
|
25
|
+
description: "ezcrypter is derived from mack-encryption (markbates) "
|
26
|
+
email:
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
files:
|
34
|
+
- lib/ezcrypter/default_worker.rb
|
35
|
+
- lib/ezcrypter/keeper.rb
|
36
|
+
- lib/ezcrypter/kernel.rb
|
37
|
+
- lib/ezcrypter/string.rb
|
38
|
+
- lib/ezcrypter.rb
|
39
|
+
- README
|
40
|
+
has_rdoc: true
|
41
|
+
homepage:
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.6
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Wraps EZCrypto library with convenience methods
|
69
|
+
test_files: []
|
70
|
+
|