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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:51:36+00:00 2026-05-24T04:51:36+00:00

I am trying to replicate the encryption logic found in a Java library in

  • 0

I am trying to replicate the encryption logic found in a Java library in a C# application.

The Java contains two methods which I have managed to replicate in C#. I get the same results in each program for any set of data.

createKey(byte data1[], MessageDigest md);
createIV(byte data2[], MessageDigest md);

The logic to generate the key and IV in Java is as follows:

public Cipher getCipher(byte[] password) {

    MessageDigest md = MessageDigest.getInstance("SHA-1");

    byte keyData[] = createKey(byte[] password, md);

     SecretKey secretKey = 
        SecretKeyFactory.getInstance("DESede").
        generateSecret(new DESedeKeySpec(keyData[]));

    IVSpec ivspec = createIV(secretKey.getEncoded(), md);

    Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
    cipher.init(1, secretKey, ivSpec, md);

    return cipher;
}

Let’s say I have the follow:

Java Key HEX:       9c 3a 79 df ba 49 86 0 ed 58 1 d8 9b a7 94 0 bb 3e 8f 80 4d 67 0 0

When I build the secretKey and then call secretKey.getEncoded() I get:

Java Encoded Key: : 9d 3b 79 df ba 49 86 1 ec 58 1 d9 9b a7 94 1 ba 3e 8f 80 4c 67 1 1     

Because I don’t know what the SecretKey is doing internally I don’t know how to replicate this in C#.

My current C# code looks like this:

    public static ICryptoTransform createCryptoTransform(String password)
    {

        ICryptoTransform ct = null;

        byte[] keyData = createKey(password);
        byte[] ivData = createInitialisationVector(keyData);

        printByteArray("keyData", keyData);
        printByteArray("ivData", ivData);

        TripleDESCryptoServiceProvider tdcsp = new TripleDESCryptoServiceProvider();

        tdcsp.Key = keyData; / This seems to be ignored by CreateEncryptor method below
        tdcsp.KeySize = 192;            
        tdcsp.IV = ivData; // This seems to be ignored by CreateEncryptor method below
        tdcsp.Mode = CipherMode.CBC;   
        tdcsp.Padding = PaddingMode.PKCS7; // PKCS5 and PKCS7 provide the same padding scheme

        ct = tdcsp.CreateEncryptor(keyData, ivData);

        return ct;

    }

As you can see, I’m using the ivData[] created from the unencoded key.

Everything works, that is I get the same encrypted result, if I pass the same IV data in when creating the encryptor but unfortunately I cannot modify how it generates it’s IVSpec.

What is SecretKey doing internally and how do I replicate this in C#?

  • 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-24T04:51:37+00:00Added an answer on May 24, 2026 at 4:51 am

    DES (and DESede) both derive 56 bits of key material from 64 bit input. The remaining 8 bits are used as parity check bits here. The source code shows you how Java handles this, you can apply the same in C#.

    See also the section at the beginning of FIPS 46-3.

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

Sidebar

Related Questions

Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to get my css / C# functions to look like this: body {
Trying to make a MySQL-based application support MS SQL, I ran into the following
Recently, I have been getting familiar with PostgreSQL(using 8.2) and found the date_trunc function
I'm trying to replicate at least some of the functionality of Workgroup Manager using
I've been trying to replicate the limit and range feature provided in MySql in
I am trying to replicate this using PHP: 2011-03-30;0;0;0;0\n2011-03-30;0;0;0;0\n2011-03-30;0;0;0;0\n2011-03-30;0;0;0;0\n2011-03-30;0;0;0;0\n2011-03-30;0;0;0;0\n2011-03-30;0;0;0;0 Although when I am doing
I am trying to replicate a shell script within windows bacth. I am getting
I am trying to replicate the border of a 2d numpy array: >>> from
I'm trying to replicate an answer given in a previous thread: How to calculate

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.