Problem with copy byte[] into another byte[]

byte, c#

Solution

You need to create a longer byte array to contain both the salt and the password:

    byte[] result = new byte[salt.Length + password.Length];
    salt.CopyTo(result, 0);
    password.CopyTo(result, salt.Length);

Problem

I have a method to create a hashed password. However it crashes at salt.CopyTo(pwd, 0); Says that the target byte[] is too small. How do I solve the problem? ``` public static byte[] CreateHashedPassword(string password, byte[] salt) { SHA1 sha1 = SHA1.Create(); byte[] pwd = CustomHelpers.StringToByteArray(password); salt.CopyTo(pwd, 0); sha1.ComputeHash(pwd); return pwd; } ```

Original source