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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:24:54+00:00 2026-06-16T04:24:54+00:00

We are implementing some kind of auto sign on in our application and got

  • 0

We are implementing some kind of auto sign on in our application and got struck at decrypting something in C#, that was encrypted in java.

Basically, a Java app generates some kind of URL. When the users clicks on the link, I need to validate the query strings and if they match, let the user sign in.

Someone provided the java code. I need to convert the same code to C# because my app is in C#. I get errors when I implement it exactly in C#.

Here is the java decryption code :

String vParameter= "ksyR31QsRcbeJoysNOsAGBHajLKWsT00wavt9LJYGOMRC8zc_vqrNOeOlGHKJHIt3sLmFhDVw_JZKr4JT0H3Jj7_Di9bKNw99qCzMOKCXYM=";  //The string that nees to be decoded.
byte[] encryptedV = Base64.decodeBase64(vParameter);
String salt = “jkjkyt4”; // the i parameter - user’s id
String password = “^hjkh673!v@!a89mz+%5rT”; // application specific
MessageDigest digester = MessageDigest.getInstance("SHA-1");
digester.update((salt + password).getBytes("UTF-8"));
byte[] key = digester.digest();
SecretKeySpec secretKey = new SecretKeySpec(key, 2, 16, “AES”);
String appIV = "SampleIV"// application specific
IvParameterSpec iv= new IvParameterSpec(appIV.getBytes(“UTF-8”));
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
byte[] decryptedV = cipher.doFinal(encryptedV, 0, encryptedV.length);
String v = new String(decryptedV, “UTF-8”);

Here is the corresponding C# code

        string vParameter = "ksyR31QsRcbeJoysNOsAGBHajLKWsT00wavt9LJYGOMRC8zc_vqrNOeOlGHKJHIt3sLmFhDVw_JZKr4JT0H3Jj7_Di9bKNw99qCzMOKCXYM="; //v parameter
        byte[] encryptedV = Encoding.UTF8.GetBytes(vParameter);
        String salt = "jkjkyt4"; // the i parameter - user’s id
        String password = "^hjkh673!v@!a89mz+%5rT"; // application specific
        var sha1 = SHA1Managed.Create();

        byte[] keyBytes = Encoding.UTF8.GetBytes(salt + password); //salt + password
        byte[] key = sha1.ComputeHash(keyBytes);
        byte[] finalKey = { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 };
        String appIV = "SampleIV";
        byte[] iv = Encoding.UTF8.GetBytes(appIV); //iv
        Array.Copy(key, 2, finalKey, 0, 16); //key 2, 16
        AesManaged tdes = new AesManaged();
        tdes.Key = finalKey;
        tdes.Mode = CipherMode.CBC;
        tdes.Padding = PaddingMode.PKCS7;
        tdes.IV = iv;
        ICryptoTransform crypt = tdes.CreateDecryptor();
        byte[] cipher = crypt.TransformFinalBlock(encryptedV, 0, encryptedV.Length);
        string decryptedText = Convert.ToBase64String(cipher);
        return decryptedText;

What am I doing wrong? Can anyone point out the mistake?

EDIT : I’ve update the V Parameter… Note – The keys, password and IV are not real. I had to change them since I didn’t want my companies keys to be public.

EDIT 2 : Hi, I’ve updated the vParameter.. Now they are the same. The Java code is working… It’s been implemented in another app. Now, I have to create a similar version for my C# app. Can you guys point out any issues in C# code?

  • 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-16T04:24:56+00:00Added an answer on June 16, 2026 at 4:24 am

    You are mixing up the UTF8 en/decodings and the base64 en/decodings. Also the code as posted does not work, since the ciphertext and the IV have the wrong lengths. I suspect that is just because you changed them to avoid revealing your real data.

    Anyway, here is a Java-snippet and a C#-snippet that returns the same result:

    Java (I only changed vParameter and appIV into something that works):

    String vParameter= "Lq4aURUiyvKvEZBWMWpUr2wRSMu96E+J1UeHLTOhKEM=";  //The string that needs to be decoded.
    byte[] encryptedV = Base64.decodeBase64(vParameter.getBytes("ASCII"));
    String salt = "jkjkyt4"; // the i parameter - user’s id
    String password = "^hjkh673!v@!a89mz+%5rT"; // application specific
    MessageDigest digester = MessageDigest.getInstance("SHA-1");
    digester.update((salt + password).getBytes("UTF-8"));
    byte[] key = digester.digest();
    SecretKeySpec secretKey = new SecretKeySpec(key, 2, 16, "AES");
    String appIV = "SampleIV12345678";// application specific
    IvParameterSpec iv= new IvParameterSpec(appIV.getBytes("UTF-8"));
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
    byte[] decryptedV = cipher.doFinal(encryptedV, 0, encryptedV.length);
    String v = new String(decryptedV, "UTF-8");
    System.out.println(v); // foobarfoobarfoobarfoobarfoobar
    

    C# (decode vParameter using Base64 and decode the decrypted data as UTF-8. Also rename the AES object to aes instead of tdes.):

    string vParameter = "Lq4aURUiyvKvEZBWMWpUr2wRSMu96E+J1UeHLTOhKEM="; //v parameter
    byte[] encryptedV = Convert.FromBase64String(vParameter);
    string salt = "jkjkyt4"; // the i parameter - user’s id
    string password = "^hjkh673!v@!a89mz+%5rT"; // application specific
    var sha1 = SHA1Managed.Create();
    byte[] keyBytes = Encoding.UTF8.GetBytes(salt + password); //salt + password
    byte[] key = sha1.ComputeHash(keyBytes);
    byte[] finalKey = { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 };
    string appIV = "SampleIV12345678";
    byte[] iv = Encoding.UTF8.GetBytes(appIV); //iv
    Array.Copy(key, 2, finalKey, 0, 16); //key 2, 16
    AesManaged aes = new AesManaged();
    aes.Key = finalKey;
    aes.Mode = CipherMode.CBC;
    aes.Padding = PaddingMode.PKCS7;
    aes.IV = iv;
    ICryptoTransform crypt = aes.CreateDecryptor();
    byte[] cipher = crypt.TransformFinalBlock(encryptedV, 0, encryptedV.Length);
    string decryptedText = Encoding.UTF8.GetString(cipher);
    Console.WriteLine(decryptedText); // foobarfoobarfoobarfoobarfoobar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing some networking stuff in our project. It has been decided that
While implementing some security aspects with Spring Security, I have noticed that both Authentication
in a bash script I am implementing some functions, that take parameters The problem
I am embedding Spidermonkey in my C++ application. I need to implementing some custom
I have been trying to get our software department to adopt some kind development
I found that some application, like GoodReader or Docs to Go, once installed can
I am working on implementing something in my iOS app that I see in
I'm using PropelORM 1.6 and implementing some kind of GIS service for a project.
I'm implementing a web application that is written in C++ using CGI. Is it
I am implementing a piece of Java software that will hopefully allow for C

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.