Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TripleDES 16 Byte not working

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.

like image 236
Ndy Avatar asked Aug 18 '16 08:08

Ndy


1 Answers

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.

like image 121
Damien_The_Unbeliever Avatar answered Sep 17 '22 12:09

Damien_The_Unbeliever