Bring CryptoHelper to the state of the art for .NET 10
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.RegularExpressions;
|
||||
using AMWD.Common.Tests.Utils;
|
||||
@@ -33,7 +34,7 @@ namespace UnitTests.Common.Utilities
|
||||
#region AES
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldEncryptAesWithoutSalt() // required to test the encryption itself
|
||||
public void ShouldEncryptAesWithoutSalt()
|
||||
{
|
||||
// arrange
|
||||
using var _ = CryptographyHelperSaltMock.Create(0);
|
||||
@@ -43,7 +44,7 @@ namespace UnitTests.Common.Utilities
|
||||
string password1 = "P@ssw0rd!";
|
||||
string password2 = "P@ssw0rd";
|
||||
|
||||
byte[] expectedBytes = [0x7c, 0x7b, 0x77, 0x56, 0x91, 0x1a, 0xd9, 0xc0, 0x72, 0x70, 0x36, 0x88, 0x9f, 0xb4, 0xb5, 0xbc];
|
||||
byte[] expectedBytes = [0xda, 0xc2, 0x74, 0x2c, 0x74, 0x50, 0x8b, 0xac, 0x6c, 0xbe, 0x60, 0x8c, 0x62, 0x32, 0xc2, 0xdd];
|
||||
|
||||
// act
|
||||
byte[] cipherBytes1 = CryptographyHelper.AesEncrypt(bytes, password1);
|
||||
@@ -53,10 +54,10 @@ namespace UnitTests.Common.Utilities
|
||||
|
||||
// assert
|
||||
CollectionAssert.AreEqual(expectedBytes, cipherBytes1);
|
||||
Assert.AreEqual("ueLuhFNpCuYmx8v3hczHtg==", cipherStr1);
|
||||
Assert.AreEqual("R/Bgu4VSk9EzvXRduyn02w==", cipherStr1);
|
||||
|
||||
CollectionAssert.AreNotEqual(expectedBytes, cipherBytes2);
|
||||
Assert.AreNotEqual("ueLuhFNpCuYmx8v3hczHtg==", cipherStr2);
|
||||
Assert.AreNotEqual("R/Bgu4VSk9EzvXRduyn02w==", cipherStr2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -65,8 +66,8 @@ namespace UnitTests.Common.Utilities
|
||||
// arrange
|
||||
using var _ = CryptographyHelperSaltMock.Create(0);
|
||||
|
||||
string cipherStr = "ueLuhFNpCuYmx8v3hczHtg==";
|
||||
byte[] cipherBytes = [0x7c, 0x7b, 0x77, 0x56, 0x91, 0x1a, 0xd9, 0xc0, 0x72, 0x70, 0x36, 0x88, 0x9f, 0xb4, 0xb5, 0xbc];
|
||||
string cipherStr = "R/Bgu4VSk9EzvXRduyn02w==";
|
||||
byte[] cipherBytes = [0xda, 0xc2, 0x74, 0x2c, 0x74, 0x50, 0x8b, 0xac, 0x6c, 0xbe, 0x60, 0x8c, 0x62, 0x32, 0xc2, 0xdd];
|
||||
|
||||
string password1 = "P@ssw0rd!";
|
||||
string password2 = "P@ssw0rd";
|
||||
@@ -147,7 +148,7 @@ namespace UnitTests.Common.Utilities
|
||||
#region TripleDES
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldEncryptTdesWithoutSalt() // required to test the encryption itself
|
||||
public void ShouldEncryptTdesWithoutSalt()
|
||||
{
|
||||
// arrange
|
||||
using var _ = CryptographyHelperSaltMock.Create(0);
|
||||
@@ -157,7 +158,7 @@ namespace UnitTests.Common.Utilities
|
||||
string password1 = "P@ssw0rd!";
|
||||
string password2 = "P@ssw0rd";
|
||||
|
||||
byte[] expectedBytes = [0xbf, 0x59, 0x1f, 0x48, 0x69, 0xab, 0x18, 0xc7];
|
||||
byte[] expectedBytes = [0xcf, 0x1a, 0x60, 0x41, 0xbb, 0x69, 0x50, 0x24];
|
||||
|
||||
// act
|
||||
byte[] cipherBytes1 = CryptographyHelper.TripleDesEncrypt(bytes, password1);
|
||||
@@ -167,10 +168,10 @@ namespace UnitTests.Common.Utilities
|
||||
|
||||
// assert
|
||||
CollectionAssert.AreEqual(expectedBytes, cipherBytes1);
|
||||
Assert.AreEqual("1l74soBuuEI=", cipherStr1);
|
||||
Assert.AreEqual("EB2GFc/pIUE=", cipherStr1);
|
||||
|
||||
CollectionAssert.AreNotEqual(expectedBytes, cipherBytes2);
|
||||
Assert.AreNotEqual("1l74soBuuEI=", cipherStr2);
|
||||
Assert.AreNotEqual("EB2GFc/pIUE=", cipherStr2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -179,8 +180,8 @@ namespace UnitTests.Common.Utilities
|
||||
// arrange
|
||||
using var _ = CryptographyHelperSaltMock.Create(0);
|
||||
|
||||
string cipherStr = "1l74soBuuEI=";
|
||||
byte[] cipherBytes = [0xbf, 0x59, 0x1f, 0x48, 0x69, 0xab, 0x18, 0xc7];
|
||||
string cipherStr = "EB2GFc/pIUE=";
|
||||
byte[] cipherBytes = [0xcf, 0x1a, 0x60, 0x41, 0xbb, 0x69, 0x50, 0x24];
|
||||
|
||||
string password1 = "P@ssw0rd!";
|
||||
string password2 = "P@ssw0rd";
|
||||
|
||||
Reference in New Issue
Block a user