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 1
1
'use strict'
2
2
3
+ const alg = 'aes-256-gcm'
3
4
const crypto = require ( 'crypto' )
4
5
const { get, set } = require ( 'lodash' )
5
6
6
7
function EncryptedAttributes ( attributes , options ) {
7
8
options = options || { }
8
9
10
+ let prefix = Buffer . from ( `${ alg } $` ) . toString ( 'base64' )
11
+
9
12
function encryptAttribute ( obj , val ) {
10
13
// 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 ) ) ) {
13
16
return val
14
17
}
15
18
if ( typeof val !== 'string' ) {
@@ -44,8 +47,8 @@ function EncryptedAttributes (attributes, options) {
44
47
45
48
function decryptAttribute ( obj , val ) {
46
49
// 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 ) ) {
49
52
return val
50
53
}
51
54
if ( options . verifyId && ! obj . id ) {
You can’t perform that action at this time.
0 commit comments