File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def self.decrypt_sensitive_value(val = "")
15
15
aes = OpenSSL ::Cipher . new ( cipher_type )
16
16
aes . decrypt
17
17
aes . key = key [ 0 ..31 ]
18
- aes . iv = iv [ 0.15 ] if iv != nil
18
+ aes . iv = iv [ 0 .. 15 ] if iv != nil
19
19
decoded = Base64 . strict_decode64 ( "#{ val } " )
20
20
aes . update ( "#{ decoded } " ) + aes . final
21
21
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+ require_relative "../../lib/encryption"
4
+
5
+ describe Encryption do
6
+ let ( :value ) {
7
+ allow ( Encryption ) . to receive ( :key ) . and_return ( SecureRandom . bytes ( 32 ) )
8
+ allow ( Encryption ) . to receive ( :iv ) . and_return ( SecureRandom . bytes ( 16 ) )
9
+
10
+ "OMG PII"
11
+ }
12
+
13
+ it "encrypts values" do
14
+ encrypted = Encryption . encrypt_sensitive_value ( value )
15
+ expect ( Base64 . decode64 ( encrypted ) ) . not_to eq ( value )
16
+ end
17
+
18
+ it "decrypts values" do
19
+ encrypted = Encryption . encrypt_sensitive_value ( value )
20
+ decrypted = Encryption . decrypt_sensitive_value ( encrypted )
21
+
22
+ expect ( decrypted ) . to eq ( value )
23
+ end
24
+ end
You can’t perform that action at this time.
0 commit comments