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

  • SEARCH
  • Home
  • 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 77695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:52:14+00:00 2026-05-10T20:52:14+00:00

all files in ~/Cipher/nsdl/crypto can be found here java files compiled with gcj, see

  • 0

all files in ~/Cipher/nsdl/crypto can be found here java files compiled with gcj, see compile.sh

nmint@nqmk-mint ~/Cipher/nsdl/crypto $ echo test | ./cryptTest encrypt deadbeefdeadbeefdeadbeefdeadbeef deadbeef Blowfish CBC > test null Exception in thread 'main' java.lang.IllegalStateException: cipher is not for encrypting or decrypting    at javax.crypto.Cipher.update(libgcj.so.81)    at javax.crypto.CipherOutputStream.write(libgcj.so.81)    at nsdl.crypto.BlockCrypt.encrypt(cryptTest)    at nsdl.crypto.cryptTest.main(cryptTest) 

BlockCrypt.java:

package nsdl.crypto;  import java.io.*; import java.security.spec.*; import javax.crypto.*; import javax.crypto.spec.*;  public class BlockCrypt { Cipher ecipher; Cipher dcipher; byte[] keyBytes; byte[] ivBytes; SecretKey key; AlgorithmParameterSpec iv; byte[] buf = new byte[1024];  BlockCrypt(String keyStr, String ivStr, String algorithm, String mode) {     try {         ecipher = Cipher.getInstance(algorithm + '/' + mode + '/PKCS5Padding');         dcipher = Cipher.getInstance(algorithm + '/' + mode + '/PKCS5Padding');          keyBytes = hexStringToByteArray(keyStr);         ivBytes = hexStringToByteArray(ivStr);          key = new SecretKeySpec(keyBytes, algorithm);         iv = new IvParameterSpec(ivBytes);          ecipher.init(Cipher.ENCRYPT_MODE, key, iv);         dcipher.init(Cipher.DECRYPT_MODE, key, iv);     } catch (Exception e) {         System.err.println(e.getMessage());     } }  public void encrypt(InputStream in, OutputStream out) {     try {         // out: where the plaintext goes to become encrypted         out = new CipherOutputStream(out, ecipher);          // in: where the plaintext comes from         int numRead = 0;         while ((numRead = in.read(buf)) >= 0) {             out.write(buf, 0, numRead);         }         out.close();     } catch (IOException e) {         System.err.println(e.getMessage());     } }  public void decrypt(InputStream in, OutputStream out) {     try {         // in: where the plaintext come from, decrypted on-the-fly         in = new CipherInputStream(in, dcipher);          // out: where the plaintext goes         int numRead = 0;         while ((numRead = in.read(buf)) >= 0) {             out.write(buf, 0, numRead);         }         out.flush();         out.close();     } catch (IOException e) {         System.err.println(e.getMessage());     } } public static byte[] hexStringToByteArray(String s) {     int len = s.length();     byte[] data = new byte[len / 2];     for (int i = 0; i < len; i += 2) {         data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)         + Character.digit(s.charAt(i+1), 16));     }     return data; } } 

cryptTest.java:

package nsdl.crypto;  import nsdl.crypto.BlockCrypt;  public class cryptTest {  public static void main (String args[]) {     if (args.length != 5) {         System.err.println('Usage: cryptTest (encrypt|decrypt) key iv algorithm mode');         System.err.println('Takes input from STDIN. Output goes to STDOUT.');     } else {         String operation = args[0];         String key = args[1];         String iv = args[2];         String algorithm = args[3];         String mode = args[4];         BlockCrypt blockCrypt = new BlockCrypt(key, iv, algorithm, mode);         if (operation.equalsIgnoreCase('encrypt')) {             blockCrypt.encrypt(System.in, System.out);         } else if (operation.equalsIgnoreCase('decrypt')) {             blockCrypt.decrypt(System.in, System.out);         } else {             System.err.println('Invalid operation. Use (encrypt|decrypt).');         }     } } } 
  • 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. 2026-05-10T20:52:15+00:00Added an answer on May 10, 2026 at 8:52 pm

    The Cipher, ecipher, is not initialized, and it throws an IllegalStateException when you try to use it as if it were initialized in ENCRYPT_MODE.

    Note your catch block in the constructor of BlockCrypt. It is catching an exception with no message, and printing ‘null’ to System.err. Rather than aborting execution—perhaps by throwing an exception from the constructor—you keep sailing.

    Replacing System.err.println(e.getMessage()) with e.printStackTrace() or at least System.err.println(e) should give you more detail. My guess is that ecipher.init() is throwing an exception because you’re providing a 32-bit IV instead of 64 bits.

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

Sidebar

Ask A Question

Stats

  • Questions 173k
  • Answers 173k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For a given project, you can cause the visibility to… May 12, 2026 at 2:44 pm
  • Editorial Team
    Editorial Team added an answer You could use sockets - a ServerSocket can only listen… May 12, 2026 at 2:44 pm
  • Editorial Team
    Editorial Team added an answer require 'rubygems' then require 'mocha' should work in this case.… May 12, 2026 at 2:44 pm

Related Questions

The server is IIS7. Is there a way to disable web.config files in subfolders?
I develop my project at ~/Dropbox/db/. I need to move the folder continuously to
I need to manage lists with find-command. Suppose the lists have random names in
I'm making a automatic configuration script for kde and I want to replace the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.