How to use 3DES decryption in C # in OFB mode?

I need to decrypt a message that has been encrypted using 3DES in OFB mode.

I have an encrypted message. I have a key. I have an IV.

I'm on the .Net platform

An encrypted message is 24 characters long in base64. The key is 24 characters in base64. and IV is a 64-bit binary number.

Due to the lack of examples, I tried using the ECB mode example as follows:

   public static string DecryptTextFromMemory(byte[] Data, byte[] Key, byte[] IV)
    {
        try
        {
            // Create a new MemoryStream using the passed 
            // array of encrypted data.
            MemoryStream msDecrypt = new MemoryStream(Data);

            // Create a CryptoStream using the MemoryStream 
            // and the passed key and initialization vector (IV).
            CryptoStream csDecrypt = new CryptoStream(msDecrypt,
                new TripleDESCryptoServiceProvider().CreateDecryptor(Key, IV),
                CryptoStreamMode.Read);

            // Create buffer to hold the decrypted data.
            byte[] fromEncrypt = new byte[Data.Length];

            // Read the decrypted data out of the crypto stream
            // and place it into the temporary buffer.
            csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);

            //Convert the buffer into a string and return it.
            return new ASCIIEncoding().GetString(fromEncrypt);
        }
        catch (CryptographicException e)
        {
            Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
            return null;
        }
    }

This is the error I get:

A cryptographic error occurred: the specified key is not valid for this algorithm.

I tried other code examples where I changed the algorithm to OFB and it says that it is not supported.

Can anybody help me? I am obviously not at home with this material, so please be patient if I ruin something obvious.

ECB 3DES, OFB.

+3
2

API CryptoSys , Triple-DES OFB. Dunno .NET , Rijndael AES.

EDIT: , "" , Triple-DES . . OFB " ", " " , , "" "".

" " . Triple-DES ( , ) , 128 192 . , 16 24 . ; throw ArgumentException, . , , , .

, Mode TripleDesCryptoServiceProvider OFB, CryptoException , , , .NET; .NET . , ; , .NET. , COM-, , .NET. ; CryptoSys, , , , TripleDES OFB .

+2

, : " ".

, " 24 64". Base64 6 char, 144 . 3DES 64 (== DES), 128 196 . , , , .

+1

Source: https://habr.com/ru/post/1789608/


All Articles