无法将 TripleDES 切换到 CFB 或 OFB 模式

Can't switch TripleDES to CFB or OFB mode

我正在使用 TripleDES 和三种不同的模式(CBCCFBOFB)加密一些数据,如下所示:

using (TripleDES alg = TripleDES.Create())
{
    var param = GetParams();
    alg.KeySize = param.keySize;
    alg.BlockSize = param.blockSize;
    alg.Key = param.sessionKey;
    alg.IV = param.IV;
    alg.Mode = param.mode;

    using (ICryptoTransform encryptor = alg.CreateEncryptor(alg.Key, alg.IV))

每当我使用 CFBOFB 作为模式时,最后一行会引发异常 (Specified cipher mode is not valid for this algorithm.)。

我做错了什么吗?

主要是因为.Net Core 不支持。 参见 https://github.com/dotnet/runtime/pull/38211

除非您正在处理遗留代码,否则您应该使用 AES 而不是 3DES。