Skip to content

Instantly share code, notes, and snippets.

@bricef
Created April 21, 2012 18:04
Show Gist options
  • Select an option

  • Save bricef/2438865 to your computer and use it in GitHub Desktop.

Select an option

Save bricef/2438865 to your computer and use it in GitHub Desktop.
Pad a byte[] to a given block size
public static byte[] padBytes(byte[] str, int blocksize){
byte[] barr;
if (str.length > blocksize){
int padbytes = str.length % blocksize ;
barr = new byte[str.length + (blocksize-padbytes)];
}else{
barr = new byte[blocksize];
}
System.arraycopy(str, 0, barr, 0, str.length);
for (int i = str.length; i < barr.length; i++){
barr[i]=0;
}
return barr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment