opensecret 0.0.962 → 0.0.988
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -10
- data/bin/opensecret +3 -4
- data/bin/ops +5 -0
- data/lib/extension/string.rb +114 -0
- data/lib/factbase/facts.opensecret.io.ini +9 -21
- data/lib/interprete/begin.rb +232 -0
- data/lib/interprete/cmd.rb +621 -0
- data/lib/{plugins/usecases/unlock.rb → interprete/export.rb} +25 -70
- data/lib/interprete/init.rb +205 -0
- data/lib/interprete/key.rb +119 -0
- data/lib/interprete/open.rb +148 -0
- data/lib/{plugins/usecases → interprete}/put.rb +19 -6
- data/lib/{plugins/usecases → interprete}/safe.rb +2 -1
- data/lib/{plugins/usecases/lock.rb → interprete/seal.rb} +24 -34
- data/lib/interprete/set.rb +46 -0
- data/lib/interprete/use.rb +43 -0
- data/lib/interpreter.rb +165 -0
- data/lib/keytools/binary.map.rb +245 -0
- data/lib/keytools/digester.rb +245 -0
- data/lib/keytools/doc.conversion.to.ones.and.zeroes.ruby +179 -0
- data/lib/keytools/doc.rsa.radix.binary-mapping.ruby +190 -0
- data/lib/keytools/doc.star.schema.strategy.txt +77 -0
- data/lib/keytools/doc.using.pbkdf2.kdf.ruby +95 -0
- data/lib/keytools/doc.using.pbkdf2.pkcs.ruby +266 -0
- data/lib/keytools/kdf.bcrypt.rb +180 -0
- data/lib/keytools/kdf.pbkdf2.rb +164 -0
- data/lib/keytools/key.data.rb +227 -0
- data/lib/keytools/key.derivation.rb +341 -0
- data/lib/keytools/key.module.rb +140 -0
- data/lib/keytools/key.rb +481 -0
- data/lib/logging/gem.logging.rb +1 -2
- data/lib/modules/cryptology.md +43 -0
- data/lib/{plugins/ciphers → modules/cryptology}/aes-256.rb +6 -0
- data/lib/{crypto → modules/cryptology}/amalgam.rb +6 -0
- data/lib/modules/cryptology/blowfish.rb +130 -0
- data/lib/modules/cryptology/cipher.rb +207 -0
- data/lib/modules/cryptology/collect.rb +118 -0
- data/lib/{plugins → modules/cryptology}/crypt.io.rb +5 -0
- data/lib/{crypto → modules/cryptology}/engineer.rb +7 -1
- data/lib/{crypto → modules/cryptology}/open.bcrypt.rb +0 -0
- data/lib/modules/mappers/collateral.rb +282 -0
- data/lib/modules/mappers/dictionary.rb +288 -0
- data/lib/modules/mappers/envelope.rb +127 -0
- data/lib/modules/mappers/settings.rb +170 -0
- data/lib/modules/storage/coldstore.rb +186 -0
- data/lib/{opensecret/plugins.io/git/git.flow.rb → modules/storage/git.store.rb} +11 -0
- data/lib/notepad/scratch.pad.rb +17 -0
- data/lib/session/fact.finder.rb +13 -0
- data/lib/session/require.gem.rb +5 -0
- data/lib/store-commands.txt +180 -0
- data/lib/version.rb +1 -1
- data/opensecret.gemspec +5 -6
- metadata +74 -29
- data/lib/crypto/blowfish.rb +0 -85
- data/lib/crypto/collect.rb +0 -140
- data/lib/crypto/verify.rb +0 -33
- data/lib/opensecret.rb +0 -236
- data/lib/plugins/cipher.rb +0 -203
- data/lib/plugins/ciphers/blowfish.rb +0 -126
- data/lib/plugins/coldstore.rb +0 -181
- data/lib/plugins/envelope.rb +0 -116
- data/lib/plugins/secrets.uc.rb +0 -94
- data/lib/plugins/usecase.rb +0 -239
- data/lib/plugins/usecases/init.rb +0 -145
- data/lib/plugins/usecases/open.rb +0 -108
- data/lib/session/attributes.rb +0 -279
- data/lib/session/dictionary.rb +0 -191
- data/lib/session/file.path.rb +0 -53
- data/lib/session/session.rb +0 -80
@@ -1,5 +1,10 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
module OpenSecret
|
4
|
+
|
5
|
+
module Store
|
6
|
+
|
7
|
+
|
3
8
|
# -- ------------------------------------------------------------------- -- #
|
4
9
|
# -- Provision the git branch involved in our present working directory. -- #
|
5
10
|
# -- The [present directory] may not relate to version control at all or -- #
|
@@ -384,5 +389,11 @@ class GitFlow
|
|
384
389
|
end
|
385
390
|
|
386
391
|
|
392
|
+
|
393
|
+
end
|
394
|
+
|
395
|
+
|
396
|
+
end
|
397
|
+
|
387
398
|
end
|
388
399
|
|
data/lib/notepad/scratch.pad.rb
CHANGED
@@ -9,6 +9,23 @@
|
|
9
9
|
|
10
10
|
class Trial
|
11
11
|
|
12
|
+
|
13
|
+
=begin
|
14
|
+
|
15
|
+
How to Sign
|
16
|
+
Signature Code
|
17
|
+
Sign Using Public/Private Keys
|
18
|
+
|
19
|
+
00 ------------------------------------
|
20
|
+
|
21
|
+
to_sign_segments = [ secured_keytext, public_key_64, @email_addr, @c[:global][:stamp_23] ]
|
22
|
+
to_sign_packet = to_sign_segments.alphanumeric_union.concat_length
|
23
|
+
signature_string = Base64.urlsafe_encode64( asymmetric_keys.sign( OpenSSL::Digest::SHA256.new, to_sign_packet ) )
|
24
|
+
|
25
|
+
00 ------------------------------------
|
26
|
+
|
27
|
+
=end
|
28
|
+
|
12
29
|
def self.ciphername
|
13
30
|
|
14
31
|
require 'openssl'
|
data/lib/session/fact.finder.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
# opensession contains basic behaviour for managing a client only
|
4
|
+
# (serverless) session. Configuration directives are read and written
|
5
|
+
# from an INI off the home directory that is created when the session
|
6
|
+
# is first initiated.
|
7
|
+
#
|
8
|
+
# The session is expected to be formally closed down and that is
|
9
|
+
# reflected by explicitly deleting the configuration file. If this
|
10
|
+
# "session over" command is not issued a reasonable time limit is
|
11
|
+
# then invoked when the next session command is issued.
|
12
|
+
#
|
13
|
+
# This "session awakening" wipes the slate clean and starts afresh
|
14
|
+
# with regard to the two dimensional array of configuration directive
|
15
|
+
# pointers.
|
3
16
|
module OpenSession
|
4
17
|
|
5
18
|
require "pp"
|
data/lib/session/require.gem.rb
CHANGED
@@ -85,6 +85,11 @@ module OpenSession
|
|
85
85
|
# @param gem_filepath [String] path to callling gem (use <tt>__FILE</tt>)
|
86
86
|
def self.now gem_filepath
|
87
87
|
|
88
|
+
|
89
|
+
############ require_relative "../cryptools/keygen"
|
90
|
+
require_relative "../interprete/cmd"
|
91
|
+
|
92
|
+
|
88
93
|
gem_basepath = File.expand_path "..", gem_filepath
|
89
94
|
|
90
95
|
log.info(x) { "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" }
|
@@ -0,0 +1,180 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
ops init john@example.com
|
4
|
+
ops open monday/menu
|
5
|
+
|
6
|
+
ops put breakfast/cereal weetabix
|
7
|
+
ops add breakfast/cereal cornflakes
|
8
|
+
|
9
|
+
if accidentally you do
|
10
|
+
|
11
|
+
ops put breakfast/cereal cocopops
|
12
|
+
|
13
|
+
it says
|
14
|
+
"I have overwritten the value of breakfast/cereal"
|
15
|
+
To alter this type "ops undo"
|
16
|
+
After every command create a backup file with session timestamp on it.
|
17
|
+
So later we can do
|
18
|
+
|
19
|
+
ops revert <<session time stamp>>
|
20
|
+
(will jump back to that point in time)
|
21
|
+
|
22
|
+
All files are deleted on close (lock) command.
|
23
|
+
|
24
|
+
================================================
|
25
|
+
Global CRUD Commands
|
26
|
+
================================================
|
27
|
+
|
28
|
+
init == creates the object
|
29
|
+
open == opens a path to the object
|
30
|
+
put == puts something inside the object (overwrites if need be)
|
31
|
+
add == add something to the object (if exists becomes a list which even allows duplicates like stack)
|
32
|
+
remove == takes out what was last put in (unless parameter declared)
|
33
|
+
close == closes object (or last opened entity -- and recurses back to another entity)
|
34
|
+
use == switches to use object with specified ID
|
35
|
+
|
36
|
+
|
37
|
+
Either Changing OBJECT - Or changing META-DATA about the OBJECT
|
38
|
+
|
39
|
+
================================================
|
40
|
+
|
41
|
+
|
42
|
+
All commands are applicable to all key objects, however there is one default object that is assumed when none is specified.
|
43
|
+
|
44
|
+
So
|
45
|
+
|
46
|
+
ops open secret abc/def
|
47
|
+
ops open store xyz
|
48
|
+
ops open domain abc.com
|
49
|
+
|
50
|
+
But if un-specific command given
|
51
|
+
|
52
|
+
ops open abc/def
|
53
|
+
|
54
|
+
Then the default "secret" is assumed.
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
==== =========================================================== ====
|
59
|
+
==== The Open Format for Command Line (or REST API) Driven Tools ====
|
60
|
+
==== =========================================================== ====
|
61
|
+
|
62
|
+
|
63
|
+
ops open domain xxxxxxxxxx
|
64
|
+
|
65
|
+
ops close == will close everything (domains, secrets ...)
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
Question "Close domain xxx or secret ...." - more than one is open
|
71
|
+
|
72
|
+
ops close domain
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
ops open store store123
|
78
|
+
|
79
|
+
ops put type git
|
80
|
+
ops put url http://asdfasdf.com
|
81
|
+
ops put credentials my.aws.keys.txt
|
82
|
+
|
83
|
+
1 = ops close 2 = ops close store 3 = ops close store123
|
84
|
+
1 = Closes everything 2 = Closes every store 3 = Closes the particular store
|
85
|
+
|
86
|
+
|
87
|
+
Then need ops use or (ops attach).
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
==================================================================================================
|
92
|
+
Key Classes
|
93
|
+
==================================================================================================
|
94
|
+
|
95
|
+
domain
|
96
|
+
store
|
97
|
+
session (etcd or redis or ...)
|
98
|
+
session (think about services jvms stuff that can be started and then referred to)
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
ops config store --url=/home/bob/crypt-store
|
103
|
+
|
104
|
+
ops config store --type=
|
105
|
+
|
106
|
+
ops safe url /home/bob/safe
|
107
|
+
ops safe url /media/phone/ops-data
|
108
|
+
|
109
|
+
ops safe type git
|
110
|
+
ops safe url https://my.domain.com/storage/
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
ops base /home/bob/credentials
|
115
|
+
ops safe
|
116
|
+
|
117
|
+
|
118
|
+
ops use domainxyz
|
119
|
+
ops use safe x123
|
120
|
+
ops use base 4sdfgy
|
121
|
+
|
122
|
+
|
123
|
+
ops configure safe/url https://www.asdf.com/asdfa.git
|
124
|
+
|
125
|
+
ops configure safe/id blue.usb.key
|
126
|
+
ops configure blue.usb.key safe/type file
|
127
|
+
ops configure safe
|
128
|
+
|
129
|
+
|
130
|
+
==================================================================================================
|
131
|
+
==================================================================================================
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
To Connect to Samsung S8 (or any other Android Device) - on Ubuntu
|
137
|
+
|
138
|
+
Most times it will be here
|
139
|
+
cd /run/user/1000/gvfs/
|
140
|
+
|
141
|
+
Then something like this
|
142
|
+
cd /run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C015%5D
|
143
|
+
(but changes)
|
144
|
+
|
145
|
+
olooks like this
|
146
|
+
mtp://[usb:001,010]/Phone/OSX
|
147
|
+
|
148
|
+
mtp:host=%5Busb%3A001%2C015%5D
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
Do ls hardware then scroll to usb section it may look like this on one of them.
|
153
|
+
sudo lshw
|
154
|
+
|
155
|
+
*-usb:0
|
156
|
+
description: Generic USB device
|
157
|
+
product: SAMSUNG_Android
|
158
|
+
vendor: SAMSUNG
|
159
|
+
physical id: 1
|
160
|
+
bus info: usb@1:1
|
161
|
+
version: 4.00
|
162
|
+
serial: 9889db344b4436374d
|
163
|
+
capabilities: usb-2.10
|
164
|
+
configuration: driver=usbfs maxpower=64mA speed=480Mbit/s
|
165
|
+
|
166
|
+
|
167
|
+
very useful
|
168
|
+
sudo apt-get install mtpfs
|
169
|
+
mtp-detect
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
if open in nautilus
|
174
|
+
lsof -c nautilus
|
175
|
+
|
176
|
+
|
177
|
+
Try these commands
|
178
|
+
|
179
|
+
sudo fdisk -l
|
180
|
+
sudo cat /etc/fstab
|
data/lib/version.rb
CHANGED
data/opensecret.gemspec
CHANGED
@@ -21,15 +21,14 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.metadata["yard.run"] = "yri"
|
23
23
|
spec.bindir = "bin"
|
24
|
-
spec.executables = ['opensecret']
|
24
|
+
spec.executables = ['opensecret', 'ops']
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
-
spec.add_dependency 'inifile'
|
28
|
-
spec.add_dependency 'thor'
|
27
|
+
spec.add_dependency 'inifile', '~> 3.0'
|
28
|
+
spec.add_dependency 'thor', '~> 0.2'
|
29
|
+
spec.add_dependency 'macaddr'
|
30
|
+
spec.add_dependency 'bcrypt'
|
29
31
|
|
30
32
|
spec.add_development_dependency "bundler", "~> 1.16"
|
31
|
-
#### in standard library ==> spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
#### in standard library ==> spec.add_development_dependency "minitest", "~> 5.0"
|
33
|
-
|
34
33
|
|
35
34
|
end
|
metadata
CHANGED
@@ -1,17 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opensecret
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.988
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Apollo Akora
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inifile
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: macaddr
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
45
|
- - ">="
|
@@ -25,7 +53,7 @@ dependencies:
|
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
56
|
+
name: bcrypt
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - ">="
|
@@ -60,6 +88,7 @@ email:
|
|
60
88
|
- apolloakora@gmail.com
|
61
89
|
executables:
|
62
90
|
- opensecret
|
91
|
+
- ops
|
63
92
|
extensions: []
|
64
93
|
extra_rdoc_files: []
|
65
94
|
files:
|
@@ -72,12 +101,7 @@ files:
|
|
72
101
|
- README.md
|
73
102
|
- Rakefile
|
74
103
|
- bin/opensecret
|
75
|
-
-
|
76
|
-
- lib/crypto/blowfish.rb
|
77
|
-
- lib/crypto/collect.rb
|
78
|
-
- lib/crypto/engineer.rb
|
79
|
-
- lib/crypto/open.bcrypt.rb
|
80
|
-
- lib/crypto/verify.rb
|
104
|
+
- bin/ops
|
81
105
|
- lib/exception/cli.error.rb
|
82
106
|
- lib/exception/errors/cli.errors.rb
|
83
107
|
- lib/extension/array.rb
|
@@ -86,32 +110,53 @@ files:
|
|
86
110
|
- lib/extension/hash.rb
|
87
111
|
- lib/extension/string.rb
|
88
112
|
- lib/factbase/facts.opensecret.io.ini
|
113
|
+
- lib/interprete/begin.rb
|
114
|
+
- lib/interprete/cmd.rb
|
115
|
+
- lib/interprete/export.rb
|
116
|
+
- lib/interprete/init.rb
|
117
|
+
- lib/interprete/key.rb
|
118
|
+
- lib/interprete/open.rb
|
119
|
+
- lib/interprete/put.rb
|
120
|
+
- lib/interprete/safe.rb
|
121
|
+
- lib/interprete/seal.rb
|
122
|
+
- lib/interprete/set.rb
|
123
|
+
- lib/interprete/use.rb
|
124
|
+
- lib/interpreter.rb
|
125
|
+
- lib/keytools/binary.map.rb
|
126
|
+
- lib/keytools/digester.rb
|
127
|
+
- lib/keytools/doc.conversion.to.ones.and.zeroes.ruby
|
128
|
+
- lib/keytools/doc.rsa.radix.binary-mapping.ruby
|
129
|
+
- lib/keytools/doc.star.schema.strategy.txt
|
130
|
+
- lib/keytools/doc.using.pbkdf2.kdf.ruby
|
131
|
+
- lib/keytools/doc.using.pbkdf2.pkcs.ruby
|
132
|
+
- lib/keytools/kdf.bcrypt.rb
|
133
|
+
- lib/keytools/kdf.pbkdf2.rb
|
134
|
+
- lib/keytools/key.data.rb
|
135
|
+
- lib/keytools/key.derivation.rb
|
136
|
+
- lib/keytools/key.module.rb
|
137
|
+
- lib/keytools/key.rb
|
89
138
|
- lib/logging/gem.logging.rb
|
139
|
+
- lib/modules/cryptology.md
|
140
|
+
- lib/modules/cryptology/aes-256.rb
|
141
|
+
- lib/modules/cryptology/amalgam.rb
|
142
|
+
- lib/modules/cryptology/blowfish.rb
|
143
|
+
- lib/modules/cryptology/cipher.rb
|
144
|
+
- lib/modules/cryptology/collect.rb
|
145
|
+
- lib/modules/cryptology/crypt.io.rb
|
146
|
+
- lib/modules/cryptology/engineer.rb
|
147
|
+
- lib/modules/cryptology/open.bcrypt.rb
|
148
|
+
- lib/modules/mappers/collateral.rb
|
149
|
+
- lib/modules/mappers/dictionary.rb
|
150
|
+
- lib/modules/mappers/envelope.rb
|
151
|
+
- lib/modules/mappers/settings.rb
|
152
|
+
- lib/modules/storage/coldstore.rb
|
153
|
+
- lib/modules/storage/git.store.rb
|
90
154
|
- lib/notepad/scratch.pad.rb
|
91
|
-
- lib/opensecret.rb
|
92
|
-
- lib/opensecret/plugins.io/git/git.flow.rb
|
93
|
-
- lib/plugins/cipher.rb
|
94
|
-
- lib/plugins/ciphers/aes-256.rb
|
95
|
-
- lib/plugins/ciphers/blowfish.rb
|
96
|
-
- lib/plugins/coldstore.rb
|
97
|
-
- lib/plugins/crypt.io.rb
|
98
|
-
- lib/plugins/envelope.rb
|
99
|
-
- lib/plugins/secrets.uc.rb
|
100
|
-
- lib/plugins/usecase.rb
|
101
|
-
- lib/plugins/usecases/init.rb
|
102
|
-
- lib/plugins/usecases/lock.rb
|
103
|
-
- lib/plugins/usecases/open.rb
|
104
|
-
- lib/plugins/usecases/put.rb
|
105
|
-
- lib/plugins/usecases/safe.rb
|
106
|
-
- lib/plugins/usecases/unlock.rb
|
107
|
-
- lib/session/attributes.rb
|
108
|
-
- lib/session/dictionary.rb
|
109
155
|
- lib/session/fact.finder.rb
|
110
|
-
- lib/session/file.path.rb
|
111
156
|
- lib/session/require.gem.rb
|
112
|
-
- lib/session/session.rb
|
113
157
|
- lib/session/time.stamp.rb
|
114
158
|
- lib/session/user.home.rb
|
159
|
+
- lib/store-commands.txt
|
115
160
|
- lib/version.rb
|
116
161
|
- opensecret.gemspec
|
117
162
|
homepage: https://www.eco-platform.co.uk
|
data/lib/crypto/blowfish.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class BF < Struct.new(:key, :pad_with_spaces)
|
6
|
-
def encrypt(str)
|
7
|
-
cipher = OpenSSL::Cipher.new('bf-ecb').encrypt
|
8
|
-
if pad_with_spaces
|
9
|
-
str += " " until str.bytesize % 8 == 0
|
10
|
-
cipher.padding = 0
|
11
|
-
end
|
12
|
-
cipher.key = key
|
13
|
-
binary_data = cipher.update(str) << cipher.final
|
14
|
-
hex_encoded = binary_data.unpack('H*').first
|
15
|
-
end
|
16
|
-
|
17
|
-
def decrypt(hex_encoded)
|
18
|
-
cipher = OpenSSL::Cipher.new('bf-ecb').decrypt
|
19
|
-
cipher.padding = 0 if pad_with_spaces
|
20
|
-
cipher.key = key
|
21
|
-
binary_data = [hex_encoded].pack('H*')
|
22
|
-
str = cipher.update(binary_data) << cipher.final
|
23
|
-
str.force_encoding(Encoding::UTF_8)
|
24
|
-
str
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
=begin
|
29
|
-
# Choose the encryption key. Its length must be a multiple of 8 and no longer than 56
|
30
|
-
bf = BF.new("x"*56, true)
|
31
|
-
sentence = ARGV[0] || "foo bar foo bar foo bar foo bar foo bar foo bar baz"
|
32
|
-
encrypted = bf.encrypt(sentence)
|
33
|
-
puts encrypted.length
|
34
|
-
puts sentence.inspect
|
35
|
-
puts "Encrypt: #{encrypted}"
|
36
|
-
puts "Decoded: #{bf.decrypt encrypted}"
|
37
|
-
=end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
=begin
|
42
|
-
require 'openssl'
|
43
|
-
module Blowfish
|
44
|
-
def self.cipher(mode, key, data)
|
45
|
-
cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').send(mode)
|
46
|
-
cipher.key = Digest::SHA256.digest(key)
|
47
|
-
cipher.update(data) << cipher.final
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.encrypt(key, data)
|
51
|
-
cipher(:encrypt, key, data)
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.decrypt(key, text)
|
55
|
-
cipher(:decrypt, key, text)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
if $0 == __FILE__
|
60
|
-
p "text" == Blowfish.decrypt("key", Blowfish.encrypt("key", "text"))
|
61
|
-
end
|
62
|
-
=end
|
63
|
-
|
64
|
-
=begin
|
65
|
-
module Blowfish
|
66
|
-
def self.cipher(mode, key, data)
|
67
|
-
cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').send(mode)
|
68
|
-
cipher.key = Digest::SHA256.digest(key)
|
69
|
-
cipher.update(data) << cipher.final
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.encrypt(key, data)
|
73
|
-
cipher(:encrypt, key, data)
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.decrypt(key, text)
|
77
|
-
cipher(:decrypt, key, text)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
if $0 == __FILE__
|
82
|
-
p "text" == Blowfish.decrypt("key", Blowfish.encrypt("key", "text"))
|
83
|
-
end
|
84
|
-
|
85
|
-
=end
|