在 C# 中使用 AES 进行确定性加密

Deterministic Encryption using AES in C#

我需要一种确定性加密算法,我可以在社会安全号码上使用我将加密存储在 MongoDB 中并且需要能够搜索它们。

我想到的是使用 AES,但有目的地使用不变的 IV 对其进行 gimp。我只是想确保我没有完全破坏加密,只做我需要做的事情来启用搜索。

总而言之,如果您得到了如下所示加密的 SSN 的数据库转储,您是否能够在不知道 IV 和密钥的情况下通过某种攻击获得明文?如果我传入作为第二个密钥的 IV(而不是硬编码)会有帮助吗?

这是我的

的跟进
public class DeterministicAes
{
    //random 16 byte iv
    private static readonly string DeterministicIv = "YO9FhYEIpGd28mJNupCjvg==";

    public static string SimpleEncryptWithPassword(string secretMessage, string password)
    {
        if (String.IsNullOrEmpty(secretMessage))
            throw new ArgumentException("Secret Message Required!", "secretMessage");
        var key = Convert.FromBase64String(password);
        var iv = Convert.FromBase64String(DeterministicIv);
        var cipherText = EncryptStringToBytes_Aes(secretMessage, key, iv);
        return Convert.ToBase64String(cipherText);
    }

    public static string SimpleDecryptWithPassword(string cipherText, string password)
    {
        if (String.IsNullOrEmpty(cipherText))
            throw new ArgumentException("Secret Message Required!", "cipherText");
        var cipherTextBytes = Convert.FromBase64String(cipherText);
        var key = Convert.FromBase64String(password);
        var iv = Convert.FromBase64String(DeterministicIv);
        return DecryptStringFromBytes_Aes(cipherTextBytes, key, iv);
    }

    //Credit: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aes?view=netframework-4.7.2#examples
    static byte[] EncryptStringToBytes_Aes(string plainText, byte[] key, byte[] iv) {}

    static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV) {}
}

AES-SIV as suggested and kindly explained on the Crypto sub-site一起去了