?
Solved

8- byte array Intialization Vector

Posted on 2009-05-20
4
Medium Priority
?
825 Views
Last Modified: 2013-11-25
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) 
Padding Mode : PKCS7 
 
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]

Open in new window

0
Comment
Question by:hameeds
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
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

by:hameeds
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);			
		}

Open in new window

0
 
LVL 86

Accepted Solution

by:
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

by:CEHJ
ID: 24442288
Good - progress :-)
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Read about why it is more lucrative for an IT company to participate in government projects.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question