basic_ssl 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/basic_ssl.rb +11 -3
  2. metadata +1 -1
data/lib/basic_ssl.rb CHANGED
@@ -4,15 +4,23 @@ require 'base64'
4
4
  module BasicSSL
5
5
 
6
6
  class << self
7
-
7
+
8
8
  ## Returns an Base64 encoded string with encryption
9
9
  def encrypt(key, string)
10
- Base64.encode64(rsa_key(key).public_encrypt(string))
10
+ aes_encrypt = OpenSSL::Cipher::Cipher.new('AES-256-CBC').encrypt
11
+ aes_encrypt.key = aes_key = aes_encrypt.random_key
12
+ crypt = aes_encrypt.update(string) << aes_encrypt.final
13
+ encrypted_key = rsa_key(key).public_encrypt(aes_key)
14
+ Base64.encode64(encrypted_key) + Base64.encode64(crypt)
11
15
  end
12
16
 
13
17
  ## Return the raw string after decryption & decoding
14
18
  def decrypt(key, string)
15
- rsa_key(key).private_decrypt(Base64.decode64(string))
19
+ encrypted_key, crypt = string.split("=").map{|a|Base64.decode64(a+'=')}
20
+ aes_key = rsa_key(key).private_decrypt(encrypted_key)
21
+ aes_decrypt = OpenSSL::Cipher::Cipher.new('AES-256-CBC').decrypt
22
+ aes_decrypt.key = aes_key
23
+ aes_decrypt.update(crypt) << aes_decrypt.final
16
24
  end
17
25
 
18
26
  ## Return a signature for the string
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basic_ssl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke