Strip bytes off the end of a byte array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting encryption. I start with a byte array of some dimension and
end with a padded byte array with junk on the end. Is there a clever way to
remove padding from the end of a byte array?

Thanks,
Fred Herring
 
Consider creating a new byte array with size = iSizeofPaddedWithoutJunk:

byte [] abytPaddedWithoutJunk = new byte[iSizeofPaddedWithoutJunk];

Then use the Buffer.BlockCopy method to copy from the original array to the
new array:

Buffer.BlockCopy(abytPaddedWithJunk, 0, abytPaddedWithoutJunk, 0,
SizeofPaddedWithoutJunk);

Finally, let the GC know to release memory associated with
abytPaddedWithJunk:

abytPaddedWithJunk = null;

HTH
mooni
 
Back
Top