Skip to content

Commit

Permalink
Use shorter keys in test mode, as they are faster.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlea committed Mar 5, 2012
1 parent bd1fe22 commit 73e175d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/cryptolocker/rsa.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require "openssl"
class Cryptolocker::RSA
KEY_LEN = 4096
KEY_BYTE_LENGTH = KEY_LEN/8
def key_byte_length
KEY_LEN/8
end

def self.generate_keys
new_key = OpenSSL::PKey::RSA.generate( KEY_LEN )
Expand All @@ -28,8 +30,8 @@ def encrypt(value)
end

def decrypt(value)
encrypted_key = value[0...KEY_BYTE_LENGTH]
data = value[KEY_BYTE_LENGTH..-1]
encrypted_key = value[0...key_byte_length]
data = value[key_byte_length..-1]
one_time_key = @key.private_decrypt(encrypted_key)
Cryptolocker::AES.decrypt(data, one_time_key)
end
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
Bundler.require(:default, :test)

require "cryptolocker"

Cryptolocker::RSA.send(:remove_const, :KEY_LEN)
Cryptolocker::RSA::KEY_LEN = 1024

0 comments on commit 73e175d

Please sign in to comment.