TripleDES 16 Byte not working
Asked Answered
S

1

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.

Sumikosumma answered 18/8, 2016 at 8:24 Comment(4)
I think your question is about .net-core rather than asp.net-core.Loretaloretta
The code for the TripleDes class itself seems to indicate that both key sizes are supported. 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.Dressel
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.Sumikosumma
@Sumikosumma 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.Heroin
D
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.

Dressel answered 18/8, 2016 at 8:54 Comment(2)
Yup that did work, did not know it reuses the first 8 bytes. Thanks for the answer.Sumikosumma
Brilliant!, Struggling from 2hrs to find a solution. Perfectly working.Ghazi

© 2022 - 2024 — McMap. All rights reserved.