lib/simple_secrets/primitives.rb in simple-secrets-1.0.0 vs lib/simple_secrets/primitives.rb in simple-secrets-2.0.0

- old
+ new

@@ -1,8 +1,9 @@ require 'openssl' require 'base64' require 'msgpack' +require 'msgpack_extensions' module SimpleSecrets # Public: Various methods useful for performing cryptographic operations. @@ -119,11 +120,11 @@ assert256BitBinary(key) cipher = OpenSSL::Cipher::AES256.new(:CBC) cipher.encrypt cipher.key = key - iv = cipher.random_iv + iv = cipher.iv = OpenSSL::Random.random_bytes(16) encrypted = ''.force_encoding('BINARY') encrypted << iv encrypted << cipher.update(binary) encrypted << cipher.final @@ -358,10 +359,10 @@ def self.assertBinary *binaries binaries.each { |binary| raise "Bad encoding. Binary string required." unless binary.instance_of?(String) && binary.encoding == Encoding::ASCII_8BIT } end def self.assert256BitBinary binary - raise '256-bit binary string required.' unless binary.size == 32 + raise "256-bit binary string required. '#{binary.unpack("H*")}'" unless binary.size == 32 end def self.assert128BitBinary binary raise '128-bit binary string required.' unless binary.size == 16 end