Skip to content

Commit

Permalink
Fix nil iv error
Browse files Browse the repository at this point in the history
  • Loading branch information
rubysamurai committed Dec 7, 2015
1 parent f1bbc9f commit 5abf3e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/cryptology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def self.encrypt_data(data, key, algorithm, iv)
cipher = ::OpenSSL::Cipher::Cipher.new(algorithm)
cipher.encrypt
cipher.key = key
cipher.iv = iv
cipher.iv = iv unless iv.nil?
cipher.update(data) + cipher.final
end

def self.decrypt_data(encrypted_data, key, algorithm, iv)
decipher = ::OpenSSL::Cipher::Cipher.new(algorithm)
decipher.decrypt
decipher.key = key
decipher.iv = iv
decipher.iv = iv unless iv.nil?
decipher.update(encrypted_data) + decipher.final
end

Expand Down
7 changes: 7 additions & 0 deletions spec/cryptology_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
SEED-CBC)

describe Cryptology do
it 'encrypts and decrypts with default arguments' do
data = 'Very confidential data with UTF-8 symbols: ♠ я ü æ'
key = 'veryLongAndSecurePassword_6154309'
encrypted = Cryptology.encrypt(data, key)
expect(Cryptology.decrypt(encrypted, key)).to eq data
end

context 'encryption' do
ALGORITHMS.each do |alg|
it "encrypts #{alg}" do
Expand Down

0 comments on commit 5abf3e1

Please sign in to comment.