dohruby 0.3.5 → 0.3.6
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/lib/doh/crypt/3des.rb +5 -2
- data/test/crypt/tc_3des.rb +17 -0
- metadata +5 -3
data/lib/doh/crypt/3des.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
require 'openssl'
|
2
|
+
require 'doh/core/string'
|
2
3
|
|
3
4
|
module DohCrypt
|
4
|
-
def self.encrypt3des(key, str)
|
5
|
+
def self.encrypt3des(key, str, encode_hex = nil)
|
5
6
|
des = OpenSSL::Cipher::Cipher.new('des-ede3')
|
6
7
|
des.encrypt
|
7
8
|
des.key = key
|
8
9
|
result = des.update(str)
|
9
10
|
result << des.final
|
11
|
+
result = result.hex_encode if encode_hex
|
10
12
|
result
|
11
13
|
end
|
12
14
|
|
13
|
-
def self.decrypt3des(key, str)
|
15
|
+
def self.decrypt3des(key, str, was_hex_encoded = nil)
|
14
16
|
des = OpenSSL::Cipher::Cipher.new('des-ede3')
|
15
17
|
des.decrypt
|
16
18
|
des.key = key
|
19
|
+
str = str.hex_decode if was_hex_encoded
|
17
20
|
result = des.update(str)
|
18
21
|
result << des.final
|
19
22
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'doh/crypt/3des'
|
3
|
+
|
4
|
+
module Doh
|
5
|
+
|
6
|
+
class TC_3des < Test::Unit::TestCase
|
7
|
+
def key
|
8
|
+
'some long key string at least 24 bytes'
|
9
|
+
end
|
10
|
+
def test_3des
|
11
|
+
assert_equal(DohCrypt.decrypt3des(key, DohCrypt.encrypt3des(key, 'smoeblahblahblah')), 'smoeblahblahblah')
|
12
|
+
assert_equal(DohCrypt.decrypt3des(key, DohCrypt.encrypt3des(key, 'smoeblahblahblah', true), true), 'smoeblahblahblah')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 6
|
9
|
+
version: 0.3.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Makani & Kem Mason
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-30 00:00:00 +13:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- test/core/tc_hash.rb
|
180
180
|
- test/core/tc_socket.rb
|
181
181
|
- test/core/tc_string.rb
|
182
|
+
- test/crypt/tc_3des.rb
|
182
183
|
- test/local_tests.rb
|
183
184
|
- test/local_tests_including_slow.rb
|
184
185
|
- test/logger/sample.rb
|
@@ -261,6 +262,7 @@ test_files:
|
|
261
262
|
- test/core/tc_hash.rb
|
262
263
|
- test/core/tc_socket.rb
|
263
264
|
- test/core/tc_string.rb
|
265
|
+
- test/crypt/tc_3des.rb
|
264
266
|
- test/local_tests.rb
|
265
267
|
- test/local_tests_including_slow.rb
|
266
268
|
- test/logger/sample.rb
|