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 7557519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:09:11+00:00 2026-05-30T12:09:11+00:00

I am running a java string encryption/decryption class that i got from the internet!

  • 0

I am running a java string encryption/decryption class that i got from the internet! Here is the class with little modification :

public class EncrypterDecrypter
{
Cipher ecipher;
Cipher dcipher;

EncrypterDecrypter(SecretKey key)
{
    try {
        ecipher = Cipher.getInstance("DES");
        dcipher = Cipher.getInstance("DES");
        ecipher.init(Cipher.ENCRYPT_MODE, key);
        dcipher.init(Cipher.DECRYPT_MODE, key);

    } catch (javax.crypto.NoSuchPaddingException e) {
    } catch (java.security.NoSuchAlgorithmException e) {
    } catch (java.security.InvalidKeyException e) {
    }
}   

}

public class EncryptionTester
{

public static void main(String[] args)
{
    try
    {
        //Generate a temporary key.
        SecretKey key = KeyGenerator.getInstance("DES").generateKey();

        //Create Encrypter/Decrypter class
        EncrypterDecrypter crypto = new EncrypterDecrypter(key);

        //More lines of code to use crypto object
    }
     catch (Exception e)
     {
     } 
}

}

My problem is that each time i create an new instance of EncrypterDecrypter class i get differents encrypted string yet the string to encrypt is still the same! My mind tells me that the problem would be the SecretKey object which keeps changing each time there is a new instance created, i would like to know how i can make the SecretKey object the same for all instances of Encrypter/Decrypter Class if that be the cause of the problem!

  • 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-05-30T12:09:12+00:00Added an answer on May 30, 2026 at 12:09 pm

    If you used the javax.crypto package, then the encrypt and decryp methods look okay.
    Try to generate your key like that:

    final SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
    final SecretKey key = skf.generateSecret(new DESKeySpec(new byte [] {/*The key*/}));
    instance.EncrypterDecrypter(key);                     //Initialization of your Cipher objects
    String encrypted = instance.encrypt("This is a test");
    System.out.println(instance.decrypt(encrypted));      //"This is a test"
    

    You should do something in the catches.

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

Sidebar

Related Questions

i've got exception, while running java class from Eclipse: java.util.MissingResourceException: Can't find bundle for
Running the following (example) code import java.io.*; public class test { public static void
When running a java applet that I made (a basic little number-guessing game), whenever
Tried running a java method that runs this oracle SQL query String query =
I now have a running Java program which only lacks of the final step,that
I am running a java program that sets up a database connection to an
I'm running a java code for getting info from a google-app-engine web service (testeserjaum.appspot.com),
Having a very basic problem here building/running a Java skeleton to make use of
I have a problem with running a Java app (B) from my app (A).
In Java 6, I have a date string that looks like 2011-11-28T21:00:00Z How would

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.