1

I have following code in C#

PasswordDeriveBytes DerivedPassword = new PasswordDeriveBytes(Password, SaltValueBytes, 
                                              HashAlgorithm, PasswordIterations);
byte[] KeyBytes = DerivedPassword.GetBytes(32);

.Net's PasswordDeriveBytes uses PBKDF1. I am using "SHA1" hashing algorithm to generate 32 byte key.

Kindly tell me how I can achieve this in crypto++. In crypto++ using PBKDF2 its generate 20 byte key. How can I make 32 byte key which C# generating.

jww
  • 97,681
  • 90
  • 411
  • 885
Siddiqui
  • 7,662
  • 17
  • 81
  • 129

1 Answers1

2

You can't, because PasswordDerivedBytes is not standard PBKDF1, while the crypto++ implementation is. Use the PBKDF2 implementation instead (Rfc2898DeriveBytes in .NET).

Henrick Hellström
  • 2,556
  • 16
  • 18
  • due to some reason I can't change the code of C#, I have to decrypt C# encrypted file in C++. In c++ I am using crypto++ library, and I get 20 bytes same as C# generated in crypto++. But unable to find rest of 12 bytes, that why I am asking these questions all over. And thanks a lot for your help, you are really helpful for me. – Siddiqui Feb 11 '12 at 19:05
  • @Siddiqui: see poupou's answer [to your earlier question](http://stackoverflow.com/questions/9231754/c-sharp-passwordderivebytes-confusion). – President James K. Polk Feb 11 '12 at 20:32
  • 2
    @Siddiqui: .NET is closed source and the algorithm used by PasswordDerivedBytes is proprietary. You could use Reflector to check the implementation, or possibly browse the Mono project in case they have already cloned it. – Henrick Hellström Feb 11 '12 at 21:02
  • @HenrickHellström they haven't cloned it (won't fix) because it is completely unsafe code and can even repeat bytes when requested in the wrong order. You may want to ask the mono guys how it works though. See poupou's answer on the previous question – Maarten Bodewes Feb 12 '12 at 14:36