Reputation: 251
In function aes_encrypt()
I want to pass only first 16 elements of an array not whole array. I am new to C#. I am getting an error that "Cannot Convert from byte to byte []"
byte[][] packet = new byte[12][];
private static byte[] key_dec_pswd = new byte[16];
for (int loop = 0; loop < noofbyte; loop++)
{
packet[addr / 512][addr % 512 + 4 + loop] = Convert.ToByte(RawDataLine.Substring((9 + (loop * 2)), 2), 16);
}
int j = packet[i].Length;
byte[] tmpPacket = new byte[j];
for (int k = 0; k < j; k++)
{
tmpPacket[k] = packet[i][k];
}
aes_encrypt(tmpPacket[16], key_dec_pswd); //Getting Error here. Cannot Convert from byte to byte []
public static void aes_encrypt(byte[] chlng_byte, byte[] key)
{
aes128_encrypt(chlng_byte, key);
}
Upvotes: 0
Views: 233
Reputation: 7061
Change
aes_encrypt(tmpPacket[16], key_dec_pswd);
to
aes_encrypt(tmpPacket, key_dec_pswd);
tmpPacket[16]
passes only byte
16 into the function instead of the intended array and thus the error.
You can also simplify the byte array copy from:
int j = packet[i].Length;
byte[] tmpPacket = new byte[j];
for (int k = 0; k < j; k++)
{
tmpPacket[k] = packet[i][k];
}
to:
var tmpPacket = packet[i].ToArray();
This does the allocation and copy all in one.
Upvotes: 2