x
Solved

# 8- byte array Intialization Vector

Posted on 2009-05-20
Medium Priority
841 Views
removed by Tiefightermod (which is sensitive and proprietary information. )
``````I'm working on Triple DES encryption with parameters in JAVA 5:

Key Size :32 bytes
Key : <key_phrase>
CipherMode : CBC (Cipher Block Chaining)

How do I create an 8- byte array initialization vector with the following values in it, { 1, 2, 3, 4, 5, 6, 7, 8} in java.

Equivalent C++ code is

// The Initialization Vector for the DES encryption routine
private readonly byte[] vector = new byte[16] { 1, 2, 3, 4, 5, 6, 7, 8};

[- Edited by SouthMod 10/01/09]
``````
0
Question by:hameeds
• 3

LVL 86

Expert Comment

ID: 24436214
Exactly the same apart from

a. the readonly - closest thing in Java is 'final'
b. numeric integral literals are treated as int, so you'll need to cast if the byte value exceeds Byte.MAX_VALUE (127 [ byte is signed - as are all other numeric types apart from char])
0

Author Comment

ID: 24436325
Please check.. if this is ok..
``````	byte[] iv = new byte[8];
int[] array = {1, 2, 3, 4, 5, 6, 7, 8};
for (int i = 0; i < 7; i++) {
int offset = (iv.length - 1 - i) * 8;
iv[i] = (byte) ((array[i] >>> offset) & 0xFF);
}
``````
0

LVL 86

Accepted Solution

CEHJ earned 150 total points
ID: 24436526
You've already got it right (in the other Java code you posted elsewhere)
0

LVL 86

Expert Comment

ID: 24442288
Good - progress :-)
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.