Created
April 21, 2012 18:04
-
-
Save bricef/2438865 to your computer and use it in GitHub Desktop.
Pad a byte[] to a given block size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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