easy-crypto 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bbf6676bf25e8ec659c4a6aefa5c6e01d05810d89f63d7003b6bfa349511a4d
4
- data.tar.gz: 5e29d59d20ccd8e532af26936dcd0c5e171de5c925e0703c393c035d6dd99dd4
3
+ metadata.gz: 71d9dc94fea524015ddc5f2494d20b6617bae68d440b5e253dd223738b7b10b8
4
+ data.tar.gz: 0d90bae4172a48debda1ba2e9c222ed0f99deb537ba5ae86201bf2ce41134bc1
5
5
  SHA512:
6
- metadata.gz: fa1a514a125fcc58efbaa8036dee9eadae419639720615ed1cc2738bd446140c9237a84c688bb84f2f7a74595747901140edb9c8245cfd3add98bb219dad08f2
7
- data.tar.gz: 7fd5eba4324cf9e16da567f7e4be5253b0477cbbbcf95c511c71e59e4d2e0bbfa36bac9bff8279832e8a678eeb7c8ca5f7abc02a9d060122e1750ffa653d9530
6
+ metadata.gz: 88db5fd08c7d5ecbcc4dc6695d848d2a052afa41be8e0c0d78a0b3a3572ad60d3eb25016346856bddbad2e964b6e57de9e5518ef24293a85c150b612a15b5e61
7
+ data.tar.gz: 6a2f42b3f6c2c8dd3148068c213591537fc832bc58842f039a5837567774cb64cc538bf81b757d68e6b2f3ef21bbf68b24ec04b55bb9106a2d86cd6c1acae416
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy-crypto (0.0.1)
4
+ easy-crypto (0.0.2)
5
5
  openssl (~> 2.1.1, >= 2.1.1)
6
6
 
7
7
  GEM
@@ -16,7 +16,7 @@ module EasyCrypto
16
16
 
17
17
  encrypted = cipher.update(plaintext) + cipher.final
18
18
 
19
- Base64.encode64(key.salt + iv + encrypted + cipher.auth_tag)
19
+ Base64.strict_encode64(key.salt + iv + encrypted + cipher.auth_tag)
20
20
  end
21
21
 
22
22
  private
@@ -7,6 +7,7 @@ module EasyCrypto
7
7
  ITERATION_COUNT = 10_000
8
8
  KEY_LENGTH = 32
9
9
  HASH_ALGO = 'sha256'
10
+ DEFAULT_SALT_LENGTH = 12
10
11
 
11
12
  attr_reader :key, :salt
12
13
 
@@ -15,7 +16,7 @@ module EasyCrypto
15
16
  @salt = salt
16
17
  end
17
18
 
18
- def self.generate(password, salt_length)
19
+ def self.generate(password, salt_length = DEFAULT_SALT_LENGTH)
19
20
  salt = OpenSSL::Random.random_bytes(salt_length)
20
21
  key = OpenSSL::KDF.pbkdf2_hmac(
21
22
  password,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyCrypto
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -4,4 +4,13 @@ RSpec.describe EasyCrypto::Crypto do
4
4
  it 'has a version number' do
5
5
  expect(EasyCrypto::VERSION).not_to be nil
6
6
  end
7
+
8
+ context 'encrypt' do
9
+ it 'returns encrypted text in a single line' do
10
+ ecrypto = EasyCrypto::Crypto.new
11
+ key = EasyCrypto::Key.generate('key password', 12)
12
+ encrypted = ecrypto.encrypt_with_key(key, 'plain text')
13
+ expect(encrypted).not_to include("\n")
14
+ end
15
+ end
7
16
  end
@@ -0,0 +1,18 @@
1
+ require 'easycrypto'
2
+
3
+ RSpec.describe EasyCrypto::Key do
4
+
5
+ context 'generate' do
6
+ it 'returns key with a salt of the specified length' do
7
+ key = EasyCrypto::Key.generate('key password', 24)
8
+
9
+ expect(key.salt.length).to be 24
10
+ end
11
+
12
+ it 'returns key with a 12 byte length salt' do
13
+ key = EasyCrypto::Key.generate('key password')
14
+
15
+ expect(key.salt.length).to be 12
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-crypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emarsys Security
@@ -92,6 +92,7 @@ files:
92
92
  - lib/easycrypto/key.rb
93
93
  - lib/easycrypto/version.rb
94
94
  - spec/easycrypto/crypto_spec.rb
95
+ - spec/easycrypto/key_spec.rb
95
96
  - spec/spec_helper.rb
96
97
  homepage: https://github.com/emartech/ruby-easy-crypto
97
98
  licenses: