You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calculates the HMAC of `obj` and attaches it as value of attribute `obj[hmacAttribute]`.
68
+
72
69
#### obj
73
70
71
+
Type: `Object`
72
+
73
+
The object to calculate and store the HMAC for.
74
+
74
75
#### key
75
76
77
+
Type: `String`
78
+
79
+
The key to calculate the objects HMAC.
80
+
76
81
#### hmacAttribute
77
82
83
+
Type: `String`
84
+
Default: `__hmac`
85
+
86
+
The name of the attribute to store the HMAC value in `obj`. Make sure that the name of the attribute is not overkapping with other attributes already in use.
Verifies the HMAC attached to `obj`. Returns `true` if the validation was successful, otherwise false `false`.
91
+
92
+
The verification would fail and return `false`, if...
93
+
-`obj` is null
94
+
-`obj` doesn't provide a HMAC to check against
95
+
-`obj` was manipulated: at least one attribute was changed, added or deleted (deep-inspection including all nested objects/arrays)
96
+
- the HMAC of `obj` was manipulated
97
+
80
98
#### obj
81
99
100
+
Type: `Object`
101
+
102
+
The object of which the HMAC should be verified. The given HMAC to be verified is assumed to exist as an attribute in the object itself: `obj[hmacAttribute]`.
103
+
82
104
#### key
83
105
106
+
Type: `String`
107
+
108
+
The key to calculate the objects HMAC and validate against the given one. Must be identical to the `key` that was used to create the original HMAC for the object.
109
+
84
110
#### hmacAttribute
85
111
112
+
Type: `String`
113
+
Default: `__hmac`
114
+
115
+
The name of the attribute for the HMAC value in `obj` to be verified against.
116
+
86
117
### calculateHmac(obj, key)
87
118
119
+
Calculates and returns the HMAC of `obj`.
120
+
121
+
Takes **all** of `obj` attributes into account for calculating the HMAC. So make sure that there isn't already a HMAC attribute created in the object. Otherwise this would also being used as an input for the calculation.
122
+
88
123
#### obj
89
124
125
+
Type: `Object`
126
+
127
+
The object to calculate the HMAC for.
128
+
90
129
#### key
91
130
131
+
Type: `String`
132
+
133
+
The key to calculate the objects HMAC.
134
+
92
135
## Under the hood
93
136
94
137
To create and verify the HMAC, standard [NodeJS crypto functions](https://nodejs.org/docs/latest-v12.x/api/crypto.html#crypto_class_hmac) are used.
95
138
96
139
The HMAC is generated by using the following parameters:
0 commit comments