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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:10:42+00:00 2026-06-17T10:10:42+00:00

In our application we are using Triple DES to encrypt and decrypt the data.

  • 0

In our application we are using Triple DES to encrypt and decrypt the data. We have the enc/dec code in C# which uses 24 byte key and 12 byte IV which works fine. Now we want to implement same code in java but when I use 12 byte IV, I get an error in java saying wrong IV size. When I googled around, I came to know that java uses 8 byte IV. Now I am confused as how come there is implementation difference in C# and JAVA for triple DES. Or am I missing anything?

This is something similar to our encryption code

class cTripleDES
{
// define the triple des provider
private TripleDESCryptoServiceProvider m_des = new TripleDESCryptoServiceProvider();

// define the string handler
private UTF8Encoding m_utf8 = new UTF8Encoding();

// define the local property arrays
private byte[] m_key;
private byte[] m_iv;

public cTripleDES(byte[] key, byte[] iv)
{
    this.m_key = key;
    this.m_iv = iv;
}

public byte[] Encrypt(byte[] input)
{
    return Transform(input,
           m_des.CreateEncryptor(m_key, m_iv));
}

public byte[] Decrypt(byte[] input)
{
    return Transform(input,
           m_des.CreateDecryptor(m_key, m_iv));
}

public string Encrypt(string text)
{
    byte[] input = m_utf8.GetBytes(text);
    byte[] output = Transform(input,
                    m_des.CreateEncryptor(m_key, m_iv));
    return Convert.ToBase64String(output);
}

public string Decrypt(string text)
{
    byte[] input = Convert.FromBase64String(text);
    byte[] output = Transform(input,
                    m_des.CreateDecryptor(m_key, m_iv));
    return m_utf8.GetString(output);
}

private byte[] Transform(byte[] input,
               ICryptoTransform CryptoTransform)
{
    // create the necessary streams
    MemoryStream memStream = new MemoryStream();
    CryptoStream cryptStream = new CryptoStream(memStream,
                 CryptoTransform, CryptoStreamMode.Write);
    // transform the bytes as requested
    cryptStream.Write(input, 0, input.Length);
    cryptStream.FlushFinalBlock();
    // Read the memory stream and
    // convert it back into byte array
    memStream.Position = 0;
    byte[] result = memStream.ToArray();
    // close and release the streams
    memStream.Close();
    cryptStream.Close();
    // hand back the encrypted buffer
    return result;
}

}

This is how we are utilizing it:

string IVasAString = "AkdrIFjaQrRQ";
byte[] iv = Convert.FromBase64String(IVasAString);
byte[] key = ASCIIEncoding.UTF8.GetBytes(KEY);

// instantiate the class with the arrays
cTripleDES des = new cTripleDES(key, iv);
string output = des.Encrypt("DATA TO BE ENCRYPTED");

  • 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-17T10:10:44+00:00Added an answer on June 17, 2026 at 10:10 am

    TripleDES has a 64-bit block size. You need to use an 8 byte IV in C#.

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

Sidebar

Related Questions

After a couple of months of using our application (which internally uses Jackrabbit 1.6.4
We have an ASMX web service which we invoke from our ASP.NET application using
We have written Web application using ASP.NET MVC, which will be hosted in our
So we have our J2EE application using Log4j like this public class CustomerController {
Our application downloads data from the internet using RSS but is having connection problems
Our application is using initialization code that depends on the order static code is
I have created a pdf version of our rails application using the Prawn plugin,
I have to create a query in our backend application using the parameters obtained
Our application is using ASP.net MVC and we have a question on what happens
We have a client server hosting our web application using Apache 2.2 & Tomcat

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.