pws 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/bin/pws +16 -6
- data/pws.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bin/pws
CHANGED
@@ -13,7 +13,7 @@ require 'zucker/kernel'
|
|
13
13
|
require 'zucker/version'
|
14
14
|
|
15
15
|
class PasswordSafe
|
16
|
-
VERSION = "0.1.
|
16
|
+
VERSION = "0.1.3".freeze
|
17
17
|
|
18
18
|
Entry = Struct.new :description, :password
|
19
19
|
|
@@ -171,28 +171,38 @@ class PasswordSafe
|
|
171
171
|
end
|
172
172
|
|
173
173
|
class << Encryptor = Module.new
|
174
|
-
CIPHER = '
|
174
|
+
CIPHER = 'aes-256-cbc'
|
175
175
|
|
176
|
-
def decrypt(
|
177
|
-
|
176
|
+
def decrypt( iv_and_data, pwhash )
|
177
|
+
iv, data = iv_and_data[0,16], iv_and_data[16..-1]
|
178
|
+
crypt :decrypt, data, pwhash, iv
|
178
179
|
end
|
179
180
|
|
180
181
|
def encrypt( data, pwhash )
|
181
|
-
|
182
|
+
iv = random_iv
|
183
|
+
encrypted_data = crypt :encrypt, data, pwhash, iv
|
184
|
+
iv + encrypted_data
|
182
185
|
end
|
183
186
|
|
184
187
|
def hash( plaintext )
|
185
188
|
OpenSSL::Digest::SHA512.new( plaintext ).digest
|
186
189
|
end
|
187
190
|
|
191
|
+
# you need a random iv for cbc mode. It is prepended to the encrypted text.
|
192
|
+
def random_iv
|
193
|
+
a = OpenSSL::Cipher.new CIPHER
|
194
|
+
a.random_iv
|
195
|
+
end
|
196
|
+
|
188
197
|
private
|
189
198
|
|
190
199
|
# Encrypts or decrypts the data with the password hash as key
|
191
200
|
# NOTE: encryption exceptions do not get caught!
|
192
|
-
def crypt( decrypt_or_encrypt, data, pwhash )
|
201
|
+
def crypt( decrypt_or_encrypt, data, pwhash, iv )
|
193
202
|
c = OpenSSL::Cipher.new CIPHER
|
194
203
|
c.send decrypt_or_encrypt.to_sym
|
195
204
|
c.key = pwhash
|
205
|
+
c.iv = iv
|
196
206
|
c.update( data ) << c.final
|
197
207
|
end
|
198
208
|
end
|
data/pws.gemspec
CHANGED
metadata
CHANGED