Replace legacy encryption with AES-GCM
This commit is contained in:
@@ -36,15 +36,14 @@ namespace Sacs.UnitTests.Net.Standard.Base.Helpers
|
||||
Assert.That(() => SacsEncryptionHelper.EncodePlainKey(value), Throws.TypeOf<NotSupportedException>());
|
||||
}
|
||||
|
||||
// --- Key and IV Generation ---
|
||||
// --- Key Generation ---
|
||||
|
||||
[Test]
|
||||
public void InitSymmetricEncryptionKeyIV_ReturnsAes256KeyAndBlockSizedIv()
|
||||
public void InitSymmetricEncryptionKey_ReturnsAes256Key()
|
||||
{
|
||||
(String key, String iv) = SacsEncryptionHelper.InitSymmetricEncryptionKeyIV();
|
||||
String key = SacsEncryptionHelper.InitSymmetricEncryptionKey();
|
||||
|
||||
Assert.That(Convert.FromBase64String(key), Has.Length.EqualTo(32));
|
||||
Assert.That(Convert.FromBase64String(iv), Has.Length.EqualTo(16));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -63,12 +62,13 @@ namespace Sacs.UnitTests.Net.Standard.Base.Helpers
|
||||
[TestCase("Unicode £ € 漢字 and emoji 😀")]
|
||||
public void EncryptDecrypt_RoundTripsText(String value)
|
||||
{
|
||||
(String key, String iv) = SacsEncryptionHelper.InitSymmetricEncryptionKeyIV();
|
||||
String key = SacsEncryptionHelper.InitSymmetricEncryptionKey();
|
||||
|
||||
String encrypted = SacsEncryptionHelper.Encrypt(value, iv, key);
|
||||
String decrypted = SacsEncryptionHelper.Decrypt(encrypted, iv, key);
|
||||
String encrypted = SacsEncryptionHelper.EncryptAuthenticated(value, key, "Tests:SacsEncryptionHelper");
|
||||
String decrypted = SacsEncryptionHelper.DecryptAuthenticated(encrypted, key, "Tests:SacsEncryptionHelper");
|
||||
|
||||
Assert.That(encrypted, Is.Not.EqualTo(value));
|
||||
Assert.That(encrypted, Does.StartWith(SacsAuthenticatedEncryption.EnvelopePrefix));
|
||||
Assert.That(decrypted, Is.EqualTo(value));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user