File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 11'use strict'
22
3+ const alg = 'aes-256-gcm'
34const crypto = require ( 'crypto' )
45const { get, set } = require ( 'lodash' )
56
67function EncryptedAttributes ( attributes , options ) {
78 options = options || { }
89
10+ let prefix = Buffer . from ( `${ alg } $` ) . toString ( 'base64' )
11+
912 function encryptAttribute ( obj , val ) {
1013 // Encrypted attributes are prefixed with "aes-256-gcm$", the base64
11- // encoding of which is "YWVzLTI1Ni1nY20k" . Nulls are not encrypted.
12- if ( val == null || ( typeof val === 'string' && val . startsWith ( 'YWVzLTI1Ni1nY20k' ) ) ) {
14+ // encoding of which is in `prefix` . Nulls are not encrypted.
15+ if ( val == null || ( typeof val === 'string' && val . startsWith ( prefix ) ) ) {
1316 return val
1417 }
1518 if ( typeof val !== 'string' ) {
@@ -44,8 +47,8 @@ function EncryptedAttributes (attributes, options) {
4447
4548 function decryptAttribute ( obj , val ) {
4649 // Encrypted attributes are prefixed with "aes-256-gcm$", the base64
47- // encoding of which is "YWVzLTI1Ni1nY20k" . Nulls are not encrypted.
48- if ( typeof val !== 'string' || ! val . startsWith ( 'YWVzLTI1Ni1nY20k' ) ) {
50+ // encoding of which is in `prefix` . Nulls are not encrypted.
51+ if ( typeof val !== 'string' || ! val . startsWith ( prefix ) ) {
4952 return val
5053 }
5154 if ( options . verifyId && ! obj . id ) {
You can’t perform that action at this time.
0 commit comments