I’m using dll for cryptography(des) which written by someone.Dll includes encrypt,decyrpt class,and that classes includes methods.Des required 8 bytes(64 bit) key.I describes a string for key.(a character is one byte).And then encoding bytes.
string keyText= "abcdefghsdsdfsdfsdf";
UTF8Encoding encoding = new UTF8Encoding();
byte[] keyfile = new byte[8];
keyfile = UTF8Encoding.UTF8.GetBytes(keyValue);
above way,even though i described size of byte array 8,size of byte array overflow,it s been length of string value.
Any suggestion.
Thanks.
To do it correctly, look at the PasswordDeriveBytes Class, and pick one of the overloaded methods.
Yes, you’ll have to pick a Salt but that can be a fixed value baked into your program. A Salt does not have to be kept secret.
And to answer the technical, not security related question:
This code creates 2 arrays. The first one is 8 bytes but it is immediately discarded.
GetBytes()creates a new one with a size it determines. You need to hash that array and then you can pick the first 8 of the hash, which is what PasswordDeriveBytes does for you.