mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Modified the ICryptographyProvider interface to require getters for the cipher engine and mode using their enum types
This commit is contained in:
@@ -81,5 +81,37 @@ namespace mRemoteNGTests.Security
|
||||
ActualValueDelegate<string> decryptMethod = () => _cryptographyProvider.Decrypt(cipherText, "wrongKey".ConvertToSecureString());
|
||||
Assert.That(decryptMethod, Throws.TypeOf<EncryptionException>());
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(TestCaseSources), nameof(TestCaseSources.AllEngineAndModeCombos))]
|
||||
public void GetCipherEngine(BlockCipherEngines engine, BlockCipherModes mode)
|
||||
{
|
||||
var cryptoProvider = new CryptographyProviderFactory().CreateAeadCryptographyProvider(engine, mode);
|
||||
Assert.That(cryptoProvider.CipherEngine, Is.EqualTo(engine));
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(TestCaseSources), nameof(TestCaseSources.AllEngineAndModeCombos))]
|
||||
public void GetCipherMode(BlockCipherEngines engine, BlockCipherModes mode)
|
||||
{
|
||||
var cryptoProvider = new CryptographyProviderFactory().CreateAeadCryptographyProvider(engine, mode);
|
||||
Assert.That(cryptoProvider.CipherMode, Is.EqualTo(mode));
|
||||
}
|
||||
|
||||
|
||||
private class TestCaseSources
|
||||
{
|
||||
public static IEnumerable AllEngineAndModeCombos
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var engine in Enum.GetValues(typeof(BlockCipherEngines)))
|
||||
{
|
||||
foreach (var mode in Enum.GetValues(typeof(BlockCipherModes)))
|
||||
{
|
||||
yield return new TestCaseData(engine, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@ namespace mRemoteNG.Security
|
||||
{
|
||||
int BlockSizeInBytes { get; }
|
||||
|
||||
string CipherEngine { get; }
|
||||
BlockCipherEngines CipherEngine { get; }
|
||||
|
||||
BlockCipherModes CipherMode { get; }
|
||||
|
||||
string Encrypt(string plainText, SecureString encryptionKey);
|
||||
|
||||
|
||||
@@ -38,7 +38,23 @@ namespace mRemoteNG.Security.SymmetricEncryption
|
||||
|
||||
public int BlockSizeInBytes => _aeadBlockCipher.GetBlockSize();
|
||||
|
||||
public string CipherEngine => _aeadBlockCipher.AlgorithmName;
|
||||
public BlockCipherEngines CipherEngine
|
||||
{
|
||||
get
|
||||
{
|
||||
var cipherEngine = _aeadBlockCipher.AlgorithmName.Split('/')[0];
|
||||
return (BlockCipherEngines)Enum.Parse(typeof(BlockCipherEngines), cipherEngine);
|
||||
}
|
||||
}
|
||||
|
||||
public BlockCipherModes CipherMode
|
||||
{
|
||||
get
|
||||
{
|
||||
var cipherMode = _aeadBlockCipher.AlgorithmName.Split('/')[1];
|
||||
return (BlockCipherModes)Enum.Parse(typeof(BlockCipherModes), cipherMode);
|
||||
}
|
||||
}
|
||||
|
||||
public AeadCryptographyProvider()
|
||||
{
|
||||
|
||||
@@ -13,11 +13,12 @@ namespace mRemoteNG.Security.SymmetricEncryption
|
||||
{
|
||||
public int BlockSizeInBytes { get; }
|
||||
|
||||
public string CipherEngine { get; }
|
||||
public BlockCipherEngines CipherEngine { get; }
|
||||
|
||||
public BlockCipherModes CipherMode { get; }
|
||||
|
||||
public LegacyRijndaelCryptographyProvider()
|
||||
{
|
||||
CipherEngine = "Rijndael";
|
||||
BlockSizeInBytes = 16;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user