File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -32,3 +32,13 @@ npm list @adyen/api-library // check version of library and update if needed
32
32
33
33
node calculateHmacPlatform.js 11223344D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB payload2.json
34
34
```
35
+
36
+ ### Calculate KCV of the HMAC key
37
+
38
+ Run ` calculateKcv ` passing the HMAC key:
39
+ ` node calculateKcv.js {hmacKey} `
40
+ ```
41
+ cd tools/hmac
42
+
43
+ node calculateKcv.js 00727DB817A85C8503AD29EAD1523DB869AF0E536893BB3046C92DE7CB045CB1
44
+ ```
Original file line number Diff line number Diff line change
1
+ // script to calculate the KVC of the HMAC key
2
+ //
3
+ // Run with: `node calculateKcv.js {hmacKey}
4
+ //
5
+ // cd tools/hmac
6
+ // node calculateKcv.js 00727DB817A85C8503AD29EAD1523DB869AF0E536893BB3046C92DE7CB045CB1 should return 9540DA
7
+ const crypto = require ( 'crypto' ) ;
8
+
9
+ // Ensure correct arguments
10
+ if ( process . argv . length !== 3 ) {
11
+ console . error ( "Usage: node calculateKcv.js <base64HmacKey>" ) ;
12
+ process . exit ( 1 ) ;
13
+ }
14
+
15
+ console . log ( `Calculating KCV...` ) ;
16
+
17
+ const hmacKey = process . argv [ 2 ] ;
18
+ // Convert the hex stringc
19
+ const keyBuffer = Buffer . from ( hmacKey , 'hex' ) ;
20
+
21
+ const algorithm = 'sha256' ;
22
+
23
+ const hmacSignature = crypto . createHmac ( algorithm , keyBuffer ) . update ( "00000000" ) . digest ( ) ;
24
+
25
+ // Take the last 3 bytes (6 hex characters) for the KCV
26
+ const kcv = Buffer . from ( hmacSignature . subarray ( hmacSignature . length - 3 ) ) . toString ( 'hex' ) . toUpperCase ( ) ;
27
+
28
+ console . log ( '********' ) ;
29
+ console . log ( `KCV: ${ kcv } ` ) ;
You can’t perform that action at this time.
0 commit comments