public static TheoryData <AuthenticatedEncryptionTestParams> DecryptMismatchTheoryData() { var theoryData = new TheoryData <AuthenticatedEncryptionTestParams>(); var keys128 = new List <SymmetricSecurityKey> { Default.SymmetricEncryptionKey256, Default.SymmetricEncryptionKey384, Default.SymmetricEncryptionKey512, Default.SymmetricEncryptionKey768, Default.SymmetricEncryptionKey1024 }; var keys256 = new List <SymmetricSecurityKey> { Default.SymmetricEncryptionKey512, Default.SymmetricEncryptionKey768, Default.SymmetricEncryptionKey1024 }; var keys128_256 = new List <SymmetricSecurityKey> { Default.SymmetricEncryptionKey512, Default.SymmetricEncryptionKey768, Default.SymmetricEncryptionKey1024, Default.SymmetricEncryptionKey256, Default.SymmetricEncryptionKey384 }; for (int i = 0; i < keys128.Count - 1; i++) { for (int j = i + 1; j < keys128.Count; j++) { AddDecryptMismatchTheoryData( "Test1-" + i.ToString() + "-" + j.ToString(), keys128[i], keys128[j], SecurityAlgorithms.Aes128CbcHmacSha256, SecurityAlgorithms.Aes128CbcHmacSha256, ExpectedException.SecurityTokenDecryptionFailedException(), theoryData); } } for (int i = keys128.Count - 1; i > 0; i--) { for (int j = i - 1; j > -1; j--) { AddDecryptMismatchTheoryData( "Test2-" + i.ToString() + "-" + j.ToString(), keys128[i], keys128[j], SecurityAlgorithms.Aes128CbcHmacSha256, SecurityAlgorithms.Aes128CbcHmacSha256, ExpectedException.SecurityTokenDecryptionFailedException(), theoryData); } } for (int i = 0; i < keys256.Count - 1; i++) { for (int j = i + 1; j < keys256.Count; j++) { AddDecryptMismatchTheoryData( "Test3-" + i.ToString() + "-" + j.ToString(), keys256[i], keys256[j], SecurityAlgorithms.Aes256CbcHmacSha512, SecurityAlgorithms.Aes256CbcHmacSha512, ExpectedException.SecurityTokenDecryptionFailedException(), theoryData); } } for (int i = keys256.Count - 1; i > 0; i--) { for (int j = i - 1; j > -1; j--) { AddDecryptMismatchTheoryData( "Test4-" + i.ToString() + "-" + j.ToString(), keys256[i], keys256[j], SecurityAlgorithms.Aes256CbcHmacSha512, SecurityAlgorithms.Aes256CbcHmacSha512, ExpectedException.SecurityTokenDecryptionFailedException(), theoryData); } } for (int i = 0; i < keys256.Count - 1; i++) { for (int j = 0; j < keys128.Count; j++) { AddDecryptMismatchTheoryData( "Test5-" + i.ToString() + "-" + j.ToString(), keys128[j], keys256[i], SecurityAlgorithms.Aes128CbcHmacSha256, SecurityAlgorithms.Aes256CbcHmacSha512, ExpectedException.SecurityTokenDecryptionFailedException(), theoryData); } } return(theoryData); }
private static void AddDecryptTamperedTheoryData(string testId, SymmetricSecurityKey key, string algorithm, TheoryData <AuthenticatedEncryptionTestParams> theoryData) { var authenticatedData = Guid.NewGuid().ToByteArray(); var plainText = Guid.NewGuid().ToByteArray(); var provider = new AuthenticatedEncryptionProvider(key, algorithm); var results = provider.Encrypt(plainText, authenticatedData); theoryData.Add(new AuthenticatedEncryptionTestParams { AuthenticatedData = Guid.NewGuid().ToByteArray(), DecryptAlgorithm = algorithm, DecryptKey = key, EE = ExpectedException.SecurityTokenDecryptionFailedException("IDX10650:"), EncryptAlgorithm = algorithm, EncryptKey = key, EncryptionResults = results, Provider = provider, TestId = "AddDecryptTheoryData1_" + testId }); results = provider.Encrypt(plainText, authenticatedData); TestUtilities.XORBytes(results.IV); theoryData.Add(new AuthenticatedEncryptionTestParams { AuthenticatedData = authenticatedData, DecryptAlgorithm = algorithm, DecryptKey = key, EE = ExpectedException.SecurityTokenDecryptionFailedException("IDX10650:"), EncryptAlgorithm = algorithm, EncryptKey = key, EncryptionResults = results, Provider = provider, TestId = "AddDecryptTheoryData2_" + testId }); results = provider.Encrypt(plainText, authenticatedData); TestUtilities.XORBytes(results.AuthenticationTag); theoryData.Add(new AuthenticatedEncryptionTestParams { AuthenticatedData = authenticatedData, DecryptAlgorithm = algorithm, DecryptKey = key, EE = ExpectedException.SecurityTokenDecryptionFailedException("IDX10650:"), EncryptAlgorithm = algorithm, EncryptKey = key, EncryptionResults = results, Provider = provider, TestId = "AddDecryptTheoryData3_" + testId }); results = provider.Encrypt(plainText, authenticatedData); TestUtilities.XORBytes(results.Ciphertext); theoryData.Add(new AuthenticatedEncryptionTestParams { AuthenticatedData = authenticatedData, DecryptAlgorithm = algorithm, DecryptKey = key, EE = ExpectedException.SecurityTokenDecryptionFailedException("IDX10650:"), EncryptAlgorithm = algorithm, EncryptKey = key, EncryptionResults = results, Provider = provider, TestId = "AddDecryptTheoryData4_" + testId }); }