@@ -5,14 +5,15 @@ Salt is generated at the client side for Authentication
5
5
## Calculate salt
6
6
7
7
Salt is calculated as follows:
8
+
8
9
1 . A = Create MD5 hash of ` CUSTOMER_ID `
9
10
2 . B = Concatenate string of A and ` SERVER_HASH ` shared by FinBox.
10
11
3 . C = Create an SHA-256 hash of B
11
12
4 . Salt = base64 encoded version of C
12
13
13
14
Sample code for salt generation in different languages:
14
15
15
- <CodeSwitcher :languages =" {python:'Python',go:'Go',java:'Java',php:'PHP',ruby:'Ruby',javascript:'JavaScript'} " >
16
+ <CodeSwitcher :languages =" {python:'Python',go:'Go',java:'Java',csharp:'C#', php:'PHP',ruby:'Ruby',javascript:'JavaScript'} " >
16
17
<template v-slot:java >
17
18
18
19
``` java
@@ -30,7 +31,7 @@ public class SaltGeneration {
30
31
private static String CUSTOMER_ID = " <CUSTOMER_ID>" ;
31
32
private static String SERVER_HASH = " <SERVER_HASH>" ;
32
33
33
- private static String getSaltForBody () {
34
+ public static String getSaltForBody () {
34
35
String hashedOutput = getMd5Hash(CUSTOMER_ID );
35
36
String concatString = hashedOutput + SERVER_HASH ;
36
37
String shaOutput = get256Encoded(concatString);
@@ -81,6 +82,66 @@ public class SaltGeneration {
81
82
```
82
83
83
84
</template >
85
+
86
+ <template v-slot:csharp >
87
+
88
+ ``` csharp
89
+ using System ;
90
+ using System .Security .Cryptography ;
91
+ using System .Text ;
92
+
93
+ public class SaltGeneration {
94
+
95
+ private static string HEX_255 = " x2" ;
96
+ private static string CUSTOMER_ID = " <CUSTOMER_ID>" ;
97
+ private static string SERVER_HASH = " <SERVER_HASH>" ;
98
+
99
+ public static string CreateSalt () {
100
+ string customerHash = CalculateMD5 (CUSTOMER_ID ).ToUpper ();
101
+ string intermediateHash = customerHash + SERVER_HASH ;
102
+ string shaOutput = CalculateSHA256 (intermediateHash );
103
+ return HexToBase64 (shaOutput );
104
+ }
105
+
106
+ private static string CalculateMD5 (string s ) {
107
+ using (MD5 md5 = MD5 .Create ()) {
108
+ byte [] inputBytes = Encoding .UTF8 .GetBytes (s );
109
+ byte [] hashBytes = md5 .ComputeHash (inputBytes );
110
+
111
+ StringBuilder sb = new StringBuilder ();
112
+ for (int i = 0 ; i < hashBytes .Length ; i ++ ) {
113
+ sb .Append (hashBytes [i ].ToString (HEX_255 ));
114
+ }
115
+ return sb .ToString ();
116
+ }
117
+ }
118
+
119
+ private static string CalculateSHA256 (string input ) {
120
+ using (SHA256 sha256 = SHA256 .Create ()) {
121
+ byte [] inputBytes = Encoding .UTF8 .GetBytes (input );
122
+ byte [] hashBytes = sha256 .ComputeHash (inputBytes );
123
+
124
+ StringBuilder sb = new StringBuilder ();
125
+ for (int i = 0 ; i < hashBytes .Length ; i ++ ) {
126
+ sb .Append (hashBytes [i ].ToString (HEX_255 ));
127
+ }
128
+ return sb .ToString ();
129
+ }
130
+ }
131
+
132
+ private static string HexToBase64 (string hexString ) {
133
+ int NumberChars = hexString .Length ;
134
+ byte [] bytes = new byte [NumberChars / 2 ];
135
+ for (int i = 0 ; i < NumberChars ; i += 2 ) {
136
+ bytes [i / 2 ] = Convert .ToByte (hexString .Substring (i , 2 ), 16 );
137
+ }
138
+ return Convert .ToBase64String (bytes );
139
+ }
140
+ }
141
+ ```
142
+
143
+ </template >
144
+
84
145
<template v-slot:python >
85
146
86
147
``` python
@@ -105,22 +166,22 @@ def create_salt(customer_id, server_hash):
105
166
106
167
``` go
107
168
import (
108
- " crypto/md5"
109
- " crypto/sha256"
110
- " fmt"
111
- " encoding/base64"
112
- " encoding/hex"
113
- " strings"
169
+ " crypto/md5"
170
+ " crypto/sha256"
171
+ " fmt"
172
+ " encoding/base64"
173
+ " encoding/hex"
174
+ " strings"
114
175
)
115
176
func GetSaltForCustomer (customerId string , serverHash string ) string {
116
177
hasher := md5.New ()
117
- hasher.Write ([]byte (customerId))
118
- hexHasher := hex.EncodeToString (hasher.Sum (nil ))
119
- data := strings.ToUpper (hexHasher) + serverHash
120
- newSha256 := sha256.New ()
121
- newSha256.Write ([]byte (data))
178
+ hasher.Write ([]byte (customerId))
179
+ hexHasher := hex.EncodeToString (hasher.Sum (nil ))
180
+ data := strings.ToUpper (hexHasher) + serverHash
181
+ newSha256 := sha256.New ()
182
+ newSha256.Write ([]byte (data))
122
183
finalData := base64.StdEncoding .EncodeToString (newSha256.Sum (nil ))
123
- return finalData
184
+ return finalData
124
185
}
125
186
```
126
187
@@ -175,7 +236,6 @@ function create_salt(customer_id, server_hash) {
175
236
176
237
</CodeSwitcher >
177
238
178
-
179
239
## Debug Salt Generation
180
240
181
241
You can cross check each individual step of your salt generation logic by using the following parameters
@@ -185,17 +245,14 @@ customer_id = 82169C6312B50CA8233482169F9F288F812B5C02114A6A74E9A62
185
245
server_hash = 5f8cd80c69a34b9785dc66298eabe95b
186
246
```
187
247
188
-
189
- ** Step A Result - Hexdigest of MD5Hash**
248
+ ** Step A Result - Hexdigest of MD5Hash**
190
249
191
250
` 7B85689C14D32209779241F14A09C29B `
192
251
193
-
194
- ** Step B Result - Intermediate Hash**
252
+ ** Step B Result - Intermediate Hash**
195
253
196
254
` 7B85689C14D32209779241F14A09C29B5f8cd80c69a34b9785dc66298eabe95b `
197
255
198
-
199
256
** Step C Result - Hexdigest Version**
200
257
201
258
` 2a2e163b66dbcd838bd6d122e17038e90f2ba5c0b6ca295364c84e19746ca8e4 `
0 commit comments