cryptic 1.0.0.beta.4 → 1.0.0.beta.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cryptic/encrypted_data.rb +14 -6
- data/lib/cryptic/version.rb +1 -1
- metadata +2 -2
@@ -8,8 +8,6 @@ module Cryptic
|
|
8
8
|
|
9
9
|
# A class with methods to encrypt/decrypt data
|
10
10
|
#
|
11
|
-
# @!attribute [Symbol] encoding the encoding to use
|
12
|
-
# @!attribute [String] data the encrypted data string
|
13
11
|
# @author Erran Carey <me@errancarey.com>
|
14
12
|
class EncryptedData
|
15
13
|
attr_reader :data
|
@@ -32,13 +30,18 @@ module Cryptic
|
|
32
30
|
if !public_key_file
|
33
31
|
# If no public key was provided the data should already be encrypted
|
34
32
|
@data = data
|
35
|
-
elsif File.exists?
|
33
|
+
elsif File.exists?(public_key_file.to_s)
|
36
34
|
public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
|
37
35
|
encrypted_data = public_key.public_encrypt(data)
|
38
36
|
@data = encode(encrypted_data)
|
39
37
|
else
|
40
|
-
|
38
|
+
public_key = OpenSSL::PKey::RSA.new(public_key_file)
|
39
|
+
encrypted_data = public_key.public_encrypt(data)
|
40
|
+
@data = encode(encrypted_data)
|
41
41
|
end
|
42
|
+
rescue => e
|
43
|
+
$stderr.puts e
|
44
|
+
raise Cryptic::KeyNotFound
|
42
45
|
end
|
43
46
|
|
44
47
|
# Creates a new encrypted data object from an encrypted data string
|
@@ -60,13 +63,18 @@ module Cryptic
|
|
60
63
|
# @raise [KeyNotFound] if the specified public key wasn't found on the
|
61
64
|
# file system
|
62
65
|
def decrypt(private_key_file, passphrase = nil)
|
63
|
-
if File.exists?
|
66
|
+
if File.exists?(private_key_file.to_s)
|
64
67
|
private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file), passphrase)
|
65
68
|
decoded_string = decode(@data)
|
66
69
|
private_key.private_decrypt(decoded_string)
|
67
70
|
else
|
68
|
-
|
71
|
+
private_key = OpenSSL::PKey::RSA.new(private_key_file, passphrase)
|
72
|
+
decoded_string = decode(@data)
|
73
|
+
private_key.private_decrypt(decoded_string)
|
69
74
|
end
|
75
|
+
rescue => e
|
76
|
+
$stderr.puts e
|
77
|
+
raise Cryptic::KeyNotFound
|
70
78
|
end
|
71
79
|
|
72
80
|
# @return [String] the encrypted data string
|
data/lib/cryptic/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.beta.
|
4
|
+
version: 1.0.0.beta.5
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -167,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
segments:
|
169
169
|
- 0
|
170
|
-
hash: -
|
170
|
+
hash: -577705480629066227
|
171
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
172
|
none: false
|
173
173
|
requirements:
|