Skip to content

Commit 4c1f18d

Browse files
Merge pull request #30 from Biggo89/main
Encoding improvement to manage German characters
2 parents 531d7d9 + a4a01e2 commit 4c1f18d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

Mastercard.Developer.ClientEncryption.Core/Encryption/FieldLevelEncryption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static JToken EncryptPayloadPath(JToken payloadToken, string jsonPathIn,
114114

115115
// Encrypt data at the given JSON path
116116
var inJsonString = JsonUtils.SanitizeJson(inJsonToken.ToString());
117-
var inJsonBytes = Encoding.ASCII.GetBytes(inJsonString);
117+
var inJsonBytes = Encoding.UTF8.GetBytes(inJsonString);
118118
var encryptedValueBytes = EncryptBytes(parameters.GetSecretKeyBytes(), parameters.GetIvBytes(), inJsonBytes);
119119
var encryptedValue = EncodingUtils.EncodeBytes(encryptedValueBytes, config.ValueEncoding);
120120

Mastercard.Developer.ClientEncryption.Tests/Tests/Encryption/FieldLevelEncryptionTest.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,11 @@ public void TestDecryptPayload_InteroperabilityTest()
7575
Assert.IsTrue(payload.Contains("account"));
7676
}
7777

78-
[TestMethod]
79-
public void TestEncryptPayload_Nominal()
78+
[DataTestMethod]
79+
[DataRow("{\"data\":{\"field1\":\"field1\",\"field2\":\"value2\"}}")]
80+
[DataRow("{\"data\":{\"field1\":\"Zürich\",\"field2\":\"value2\"}}")]
81+
public void TestEncryptPayload_Nominal(string payload)
8082
{
81-
// GIVEN
82-
const string payload = "{" +
83-
" \"data\": {" +
84-
" \"field1\": \"value1\"," +
85-
" \"field2\": \"value2\"" +
86-
" }," +
87-
" \"encryptedData\": {}" +
88-
"}";
8983
var config = TestUtils.GetTestFieldLevelEncryptionConfigBuilder()
9084
.WithEncryptionPath("data", "encryptedData")
9185
.WithDecryptionPath("encryptedData", "data")
@@ -107,7 +101,7 @@ public void TestEncryptPayload_Nominal()
107101
Assert.IsNotNull(encryptedDataToken["encryptedValue"]);
108102
Assert.IsNotNull(encryptedDataToken["encryptedKey"]);
109103
Assert.IsNotNull(encryptedDataToken["iv"]);
110-
TestUtils.AssertDecryptedPayloadEquals("{\"data\":{\"field1\":\"value1\",\"field2\":\"value2\"}}", encryptedPayload, config);
104+
TestUtils.AssertDecryptedPayloadEquals(payload, encryptedPayload, config);
111105
}
112106

113107
[TestMethod]

0 commit comments

Comments
 (0)