pws 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bin/pws +16 -6
  3. data/pws.gemspec +1 -1
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
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.2".freeze
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 = 'AES256'
174
+ CIPHER = 'aes-256-cbc'
175
175
 
176
- def decrypt( data, pwhash )
177
- crypt :decrypt, data, pwhash
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
- crypt :encrypt, data, pwhash
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pws}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jan Lelis"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pws
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan Lelis