runtime: TripleDES is not allowing 16 byte keys

This works on full framework, but not core. This is a simple alteration of the dotnet new to isolate the problem (only other change is to add net452 to project.json).

using System;
using System.Security.Cryptography;
using System.Text;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var d = TripleDES.Create();
            d.Key = ASCIIEncoding.ASCII.GetBytes("1234567890123456");
            Console.WriteLine("Hello World!");
        }
    }
}

Running the above under net452 works fine, but under netcoreapp10 results in:

Unhandled Exception: System.Security.Cryptography.CryptographicException: Specified key is not a valid size for this alg
orithm.
   at System.Security.Cryptography.SymmetricAlgorithm.set_Key(Byte[] value)
   at System.Security.Cryptography.TripleDES.set_Key(Byte[] value)
   at ConsoleApplication.Program.Main(String[] args)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

If it works for TripleDES.Create() out of the box on Desktop, it should work out of the box on Core.

OK, can you please do it @steveharter by EOW in rel/2.0.0 branch? (before Escrow starts)

As proposed by Damien_The_Unbeliever in this post (https://stackoverflow.com/questions/39013264/tripledes-16-byte-not-working/39013863#39013863), I’ve repeated the first 8 bytes to form a valid 24 bytes key and it worked. This is a work around but works for now.