6

I am trying to migrate some projects from .net framework 4.5 to .net core. The problem arrises when trying to migrate an old crypting/decrypting method. The method is a TripleDES with a key that is a MD5 hash. The MD5 hash always returns 16 bytes. This works well in .net framework 4.5, but in .net core in System.Security.Cryptography.Algorithms TripleDES only accepts a KeySize of 24 bytes. In 4.5 it accepts 16 bytes or 24 bytes. Are there any workarounds that i could try?

Later edit : The TripleDes class when initialized calls new TripleDesImplementation which is this . And here it is stated that the CNG does not support 128 bit keys.

Ndy
  • 326
  • 3
  • 15
  • I think your question is about .net-core rather than asp.net-core. – adem caglin Aug 18 '16 at 08:39
  • The code for the TripleDes class itself seems to indicate that [both key sizes are supported](https://github.com/dotnet/corefx/blob/d0dc5fc099946adc1035b34a8b1f6042eddb0c75/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/TripleDES.cs#L105). Obviously `TripleDes` is an abstract class so can you add some sample code that shows exactly how you're creating it and how/when an error is indicated. – Damien_The_Unbeliever Aug 18 '16 at 08:45
  • The TripleDes class when initialized calls new TripleDesImplementation which is [this](https://github.com/dotnet/corefx/blob/d0dc5fc099946adc1035b34a8b1f6042eddb0c75/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/TripleDesImplementation.cs#L20) . And here it is stated that the CNG does not support 128 bit keys. – Ndy Aug 18 '16 at 08:48
  • @Ndy Beware that 2 key (128 bit) 3DES has been deprecated by NIST. You might want to consider upgrading (to AES) *soon* rather than late. 3 key TDES only gives you ~ 112 bit of security, 2 key 3DES much less. – Maarten Bodewes Aug 18 '16 at 20:19

1 Answers1

9

Unfortunately, there's no open source version of the TripleDes implementation that is used by Framework 4.5.

However, assuming it's following normal conventions for Triple DES, that when it's supplied two keys it reuses the first key as the third key, you should be able to take your existing 16 byte key and just repeat the first 8 bytes to form a 24 byte key, and it should produce the same results as you previously obtained.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448