473,516 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encryption in java and decrypting string in C#

1 New Member
Hello I've Encrypted Hex string and Key that has been encrypted using standard AES Algorithm.
Expand|Select|Wrap|Line Numbers
  1. final String key = "=abcd!#Axd*G!pxP";         
  2. final javax.crypto.spec.SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");         
  3. final javax.crypto.Cipher cipher = Cipher.getInstance("AES");         
  4. cipher.init(Cipher.ENCRYPT_MODE, keySpec);         
  5. byte [] encryptedValue = cipher.doFinal(input.getBytes());         
  6. return new String(org.apache.commons.codec.binary.Hex.encodeHex(encryptedValue));
  7.  
Now I try to decrypt it using C# Code:
Expand|Select|Wrap|Line Numbers
  1. RijndaelManaged rijndaelCipher = new RijndaelManaged();             // Assumed Mode and padding values.             
  2. rijndaelCipher.Mode = CipherMode.ECB;             
  3. rijndaelCipher.Padding = PaddingMode.None;              // AssumedKeySize and BlockSize values.             
  4. rijndaelCipher.KeySize = 0x80;             
  5. rijndaelCipher.BlockSize = 0x80;             // Convert Hex keys to byte Array.             
  6. byte[] encryptedData = hexStringToByteArray(textToDecrypt);              
  7.  
  8. byte[] pwdBytes = Encoding.Unicode.GetBytes(key);             
  9. byte[] keyBytes = new byte[0x10];             
  10. int len = pwdBytes.Length;             
  11. if (len > keyBytes.Length)             
  12. {                 
  13. len = keyBytes.Length;             
  14. }             
  15. Array.Copy(pwdBytes, keyBytes, len);             
  16. rijndaelCipher.Key = keyBytes;            
  17. rijndaelCipher.IV = keyBytes;             // Decrypt data             
  18. byte[] plainText = rijndaelCipher.CreateDecryptor().TransformFinalBlock(encryptedData, 0, encryptedData.Length);             
  19.  
  20. str = Encoding.UTF8.GetString(plainText); 
  21.  
and
Expand|Select|Wrap|Line Numbers
  1. static private Byte[] hexStringToByteArray(string hexinput)
  2.         {
  3.             if (hexinput == String.Empty)
  4.                 return null;
  5.             if (hexinput.Length % 2 == 1)
  6.                 hexinput = "0" + hexinput;
  7.             int arr_size = hexinput.Length / 2;
  8.             Byte[] myBytes = new Byte[arr_size];
  9.             for (int i = 0; i < arr_size; i++)
  10.                 myBytes[i] = Convert.ToByte(hexinput.Substring(i * 2, 2), 16);
  11.             return myBytes;
  12.         }
  13.  
I'm not getting desired decrypted string. Where I'm going wrong. I tried with all possible combinations of mode and padding.
Mar 14 '11 #1
0 1654

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11634
by: knocker | last post by:
Hi I have a problem with JSP on websphere 5. When I try save information with swedish or danish ÅÄÖ characters, the string is cut where the first of these characters occurs. The JDK used is 1.3.1 I've tried: String CUNM = request.getParameter("CUNM").trim(); CUNM = URLDecoder.decode(CUNM,"UTF-8");
1
4600
by: Min-Koo Seo | last post by:
Hi. I have a java stored procedure whose spec is as follows: CREATE OR REPLACE FUNCTION DECODE_SEQUENCE(SEQUENCE VARCHAR2) RETURN VARCHAR2 DETERMINISTIC AS LANGUAGE JAVA NAME 'kr.ac.dke.protein.compression.SequenceCompressor.decode(java.lang.String) return java.lang.String';
1
1366
by: vbdotnetmania | last post by:
Hi, I'm trying to port java code to c#, I am not too familiar with either so forgive me for what might be a stupid question, I wish to use the java string type rather than the c# one, when I try to declare the type as java.lang.string I am not allowed, is there a way I can use the java string type rather than the c# native string type. Any help...
6
7846
by: larry mckay | last post by:
Hi, Does anyone have any simple text string encryption routines that are easy to implement? I'm trying to prevent users and system administrators from figuring out how I implement things. thanks *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
3
985
by: G Leifheit | last post by:
I'm looking for a way to Encrypt & Decrypt Data in a String Value that can be placed in a text file. All i'm finding are items that storing the encrypted value in a text file can be problematic because of special characters. I'm looking possible at SecureQuerryString, any other option? What is recommended?
1
1324
by: Ashish Jain | last post by:
Environment: .Net Framwework 2.0/SQL Server 2005 - Windows XP SP2/Windows Server 2003 My web application is a mix of ASP and ASP.Net. My "ASP" web application uses a serviced COM+ component written in C# 2.0 for authentication. The confuguration file itself is located in System32 folder as required by COM+. For reading the config file, we...
5
3425
by: Harb247 | last post by:
Hi Guys, First Post. Need some help decrypting a String / DB The company i manage recently had an argument with their lead programmer for their data base. However he has decided to have nothing to do with the company so i cannot contact him to get the info i require. Ive looked over his computer and accessed the .dat (I have no idea why...
4
5661
by: Fritjolf | last post by:
Hi. I've got a strange problem... I've made a simple program to test encryption/decryption. I use Rijndael encryption and here are the most important properties. RijndaelManaged cipher = new RijndaelManaged(); cipher.KeySize = 256; cipher.BlockSize = 256;
5
3463
by: creative1 | last post by:
hi, I am new at writing JSP and Servlets. When I compile my serverlet I get follwoing error cannot find mymbol method parseDate(java.lang.String) I have follwoing code: Code: ( text ) package admin; import java.lang.Object.*;
1
3130
by: ahmee | last post by:
this my program code these are my errors below please help me out....guys operater % cannot be applied to java.lang.String.int operater / cannot be applied to java.lang.String.int operater + cannot be applied to <any>,int import javax.swing.*; class demo {
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.