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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:17:56+00:00 2026-06-13T18:17:56+00:00

I have a problem I have been trying to solve for last three days.

  • 0

I have a problem I have been trying to solve for last three days. I have to use DES to encrypt an array of bytes to get a specific result. The default implementation of DES in Java (Javax.crypto.cipher, JDK 7, provider SunJCE version 1.7), however, seemingly does not work.
When I have the following code:


    private void testDES() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
        Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
        byte[] keyByte = convertStringToBytes("00 00 00 00 00 00 00 00");
        byte[] data = convertStringToBytes("00 00 00 00 00 00 00 00");
        Key key = new SecretKeySpec(keyByte, "DES");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        System.out.println(hexadecimalString(cipher.doFinal(data)));
    }

It prints F4 DA 4D 97 BF CF 23 D9 instead of the correct result 8C A6 4D E9 C1 B1 23 A7 (according to the test vectors : http://common-lisp.net/project/clbuild/mirror/ironclad/test-vectors/des.testvec)
The methods hexadecimalString and convertStringToBytes just transform byte to hexa and vice versa.
Could anyone please help me? After searching for a rather long time, I just don’t know what to do. Thanks in advance. Joe

  • 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-13T18:17:58+00:00Added an answer on June 13, 2026 at 6:17 pm

    I think the problem is with either convertStringToBytes or hexadecimalString.

    You can replace:

    byte[] keyByte = convertStringToBytes("00 00 00 00 00 00 00 00");
    byte[] data = convertStringToBytes("00 00 00 00 00 00 00 00");
    

    with:

    byte[] keyByte = new byte[8];
    byte[] data = new byte[8];
    

    … because in Java, arrays are initialised to zero.

    When I run the same code, but with the above (and not convertStringToBytes), then I get the expected result (8C A6 …)

    Edit:
    Since you’re still having problems, here’s a full program. The output for me is:

    8c a6 4d e9 c1 b1 23 a7 
    

    Code below:

    public class Main {
        public static void main(String[] args) throws GeneralSecurityException {
            Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
            byte[] keyByte = new byte[8];
            byte[] data = new byte[8];
            Key key = new SecretKeySpec(keyByte, "DES");
            cipher.init(Cipher.ENCRYPT_MODE, key);
            byte[] result = cipher.doFinal(data);
            StringBuilder str = new StringBuilder();
            for (byte b : result) {
                 str.append(Integer.toHexString(0xff & b)).append(' ');
            }
            System.out.println(str);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to solve this problem for three days now, it's really
During last three days I have been trying to solve Project Euler 15 in
I have been trying to understand and solve this problem for the last three
I have an interesting problem here I've been trying to solve for the last
I have a problem that I have been trying to solve since days! I
I have problem I've been trying to solve for the last couple of hours
I have been trying to solve this problem for a while, but couldn't with
I have been trying to find ways to solve the problem. Firebug said syntax
I have been trying to solve this problem all day, I googled a lot,
I have been trying to solve a programming problem, one of the modules of

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.