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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:12:33+00:00 2026-05-26T21:12:33+00:00

I am trying to decrypt in JAVA a string that was encrypted in C#.

  • 0

I am trying to decrypt in JAVA a string that was encrypted in C#.
In c# the decryption is succesffull with this method:

  AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
        aesProvider.BlockSize = 128;
        aesProvider.KeySize = 128;
        aesProvider.Key = strKey;
        aesProvider.IV = strIV;
        aesProvider.Padding = PaddingMode.PKCS7;
        aesProvider.Mode = CipherMode.CBC;

        ICryptoTransform cryptoTransform = aesProvider.CreateDecryptor(aesProvider.Key, aesProvider.IV);
        byte[] DecryptedBytes = cryptoTransform.TransformFinalBlock(EncryptedBytes, 0, EncryptedBytes.Length);
        return System.Text.Encoding.UTF8.GetString(DecryptedBytes);

What I am trying to do is convert this method to JAVA (Android), this is what I have tried, but get an error message (“Pad block corrupted”):

 try
       {
           byte[] IV = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6 };
           byte[] KEY = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6 };

           SecretKeySpec key = new SecretKeySpec(KEY, "AES/CBC/PKCS7Padding");
           Cipher cipher = Cipher.getInstance ("AES/CBC/PKCS7Padding");

           cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV));

           byte[] bytesData = Utilities.Base64Coder.decode(data);

           Log.i("bytesData", String.valueOf(bytesData.length));

           String strResult = new String(cipher.doFinal(bytesData));


            Log.i("decrypted string", strResult);
            return strResult;
        }
        catch (Exception e) {

            Log.i("decrypted FAILED", e.getMessage());
            return null;
        }

10X 🙂

  • 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-26T21:12:34+00:00Added an answer on May 26, 2026 at 9:12 pm

    For whom ever search and get to this question – this code works fine, the problem was with the key that was different between c# and Java.

    GregS – 10X for raising my attention to check it again.

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

Sidebar

Related Questions

I'm trying to make a decryption of a string in JAVA encrypted in Delphi
I am trying to decrypt data that has been encrypted previously in RSA (don't
I'm getting literally crazy trying to decrypt in JavaScript a string encrypted in PHP
I'm trying to decrypt an encrypted image in Android using this code: public class
Am trying to decrypt a key encrypted by Java Triple DES function using PHP
I'm busy trying to port Java code that looks like this Cipher rsa =
I'm trying to decrypt a file in unmanaged C++ that was previously encrypted with
I'm trying to decrypt a variable that I've encrypted from my web server and
Trying to write a couple of functions that will encrypt or decrypt a file
I'm trying to decrypt a string using mcrypt_decrypt, but I'm not sure how to

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.