Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:51:27+00:00 2026-06-12T09:51:27+00:00

I have for a few days reading this and other tutorials about javax.crypto Using

  • 0

I have for a few days reading this and other tutorials about javax.crypto
Using block modes and initialisation vectors in Java

My test code below is a Client who send data to a Server.

I read about different block modes and the CFB8 stream mode seem to be working because i split arbitrary size files up in chunks. Every chunk is 0.5MB except for the last chunk that are smaller, they are sent one after another to the Server that put the file back together.

I have a few questions:

1) Should i use Asymmetric cryptography publ/priv keys to send the SecretKeySpec password and the IV to the server before i start the transfer?

2) What are the SecretKeySpec password used for, protect the IV?

THE CLIENT encrypt data

Cipher cipher = Cipher.getInstance("AES/CFB8/NoPadding"); 
SecretKeySpec keySpec = new SecretKeySpec("password12345678".getBytes(), "AES");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);

AlgorithmParameters params = cipher.getParameters();
byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV();

out.write(iv); //Send IV to Server
out.flush();

// THE ENCRYPTET STREAM
cos = new CipherOutputStream(out, cipher);  

while ((val = byteArrayInputStream.read(buffer, 0, 1024)) > 0) {
       cos.write(buffer, 0, val);
       cos.flush();
}

cipher.doFinal()

THE SERVER decrypt data

    byte[] iv = new byte[16];
    in.read(iv);

    Cipher cipher = Cipher.getInstance("AES/CFB8/NoPadding"); 
    SecretKeySpec keySpec = new SecretKeySpec("password12345678".getBytes(), "AES");
    IvParameterSpec ivSpec = new IvParameterSpec(iv);
    cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

    cos = new CipherInputStream(in, cipher);        

   while (offset < tmpBuffer.length && (numRead=cos.read(tmpBuffer, offset,      tmpBuffer.length-offset)) >= 0) {
      offset += numRead;
      savedFileSize = savedFileSize + numRead;
   }    
   // CREATE HASH FROM THE DOWNLOAD CHUNK PART
   String retCrC = DoEncryption.getCRC32ChecksumFromArray(tmpBuffer);
   String hash2 = Long.toHexString( Long.parseLong(retCrC) );

   // TEST SO THE REMOTE HASH MATCH THE LOCAL HASH
   if(!hash1.equals(hash2)){
   ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:51:28+00:00Added an answer on June 12, 2026 at 9:51 am

    Should I use asymmetric cryptography publ/priv keys to send the SecretKeySpec password and the IV to the server before I start the transfer?

    This is broadly how SSL works, albeit usually in reverse. Any reason you couldn’t use SSL/TLS instead? Generating your own secure transfer protocol is not a trivial undertaking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading articles about state management in ASP.NET for few days for
I have been reading a lot about Ruby the past few days. Every SO
I have been reading over the last few days about assembly language, and the
Since a few days I'm unable to start resque I have tried debugging this
There have been several questions over the past few days about the proper use
I have been wrestling with this for a few days and after tons of
I have been using Subversion for a few days now and have a question...
I started reading about implementing various data structures a few days back, and got
i have been struggling with this for a few days. I have a total
I've created a question about this a few days . My solution is something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.