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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:25:12+00:00 2026-06-01T00:25:12+00:00

I want to use PBE to encrypt my data. So far, I have written

  • 0

I want to use PBE to encrypt my data. So far, I have written the following code :

    moteurCryptage = Cipher.getInstance("PBEWithMD5AndDES");

        PBEKeySpec spécifClé=new PBEKeySpec(mdp.toCharArray());
        SecretKeyFactory usineàClefs=SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey clé=null;
        try {
            clé = usineàClefs.generateSecret(spécifClé);
        } catch (InvalidKeySpecException ex) {
            Logger.getLogger(DiskUtilView.class.getName()).log(Level.SEVERE, null, ex);
        }

    moteurCryptage.init(Cipher.ENCRYPT_MODE,clé);
        byte[] paramètresEncodage;
        try {
            paramètresEncodage=moteurCryptage.getParameters().getEncoded();
        } catch (IOException ex) {
            paramètresEncodage=null;
        }

    destination=moteurCryptage.update(source1.getBytes());
    destination=moteurCryptage.doFinal(source2.getBytes());

    moteurCryptage.init(Cipher.DECRYPT_MODE,clé,paramètresEncodage);

    source=new String(moteurCryptage.doFinal(destination));

Encryption seems to work (I don’t get any error, neither during compilation nor execution) but the initialisation of the Cipher object for decryption doesn’t accept the javax.crypto.SecretKey class (compilation error). It instead asks for a java.security.key.

What can I do?

Thanks in advance for the time you will spend trying to help me.

  • 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-01T00:25:13+00:00Added an answer on June 1, 2026 at 12:25 am

    The problem is the line

    moteurCryptage.init(Cipher.DECRYPT_MODE, cle, parametresEncodage);
    

    which should be

    moteurCryptage.init(Cipher.DECRYPT_MODE, cle, moteurCryptage.getParameters());
    

    Also, as you pointed out, it then doesn’t work for some strings (works only for those really short). The problem is that when you call update(), it saves some data into the resulting byte[]. When you call doFinal() on the same variable, it overwrites the data and they are lost forever. The doFinal() method doesn’t do all the encrypting again, it only does the remaining part!

    That means, that you

    • have to concatenate the source strings before you process them
    • or you have to preserve destination after update(), make destination2 for doFinal() and then both decrypt the same way – update() destination and doFinal() destination2
    • or you can make destination and destination2, concatenate them (here’s how, e.g.) into a single completeDestination array and do decrypting doFinal() on that.

    If you would like to see the code for all the above, just say a word.

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

Sidebar

Related Questions

i want use some data from a website with web service. i have a
I use codeigniter and i want make uniqid code with php as following code(by
I want use this 1 for using Bar code or QR code scanner. I
I don't want use old Visual Basic methods in my code, and I'm confused
I want use php curl with oauth to get the JSON data from twitter
I want to use private drawable from android. for that i have downloade androi-8.jar
I don't want use ajax to load data in my grid. Theres a way
I want use ORDER BY RAND() query mysql. But I have some question want
I need to use HTML comments to store specific data, but I don't want
I have created NSMutale Array in HeroListViewController . I want use it in another

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.