RSA encryption in Java / .NET and decryption in .NET.

My application has Java and .NET clients, and my application is in .NET. My clients will send me an XML file encrypted using the RSA public key, and I need to decrypt it using .NET.

In the "Achinth Anand Gurkhi" line, the Java RSA Encryption method generates the following encrypted line:

e8s2Ap3R1AwoaKB7OPCwkf0vhAVGaQisdoq2Yo0BvwcQ7v3oVtMOVc5wsnIyNVOSZV543imwIiBer0HSXRe8PoBD4jj0tTxtLA+bdoR40oQJD2UmZ4OpAH3g92wLXYd4bVvjllcCPPc0tSr/nzEKeZHcnhf6cGpuwfKyFNbXW2vtlEfmRd+LGqlixPRlx1OnsSMNNw+u/5IBs8MauY4Uwq1Lovlgd9f/8WTOvq9ityr84vGLMRGs4wpC7+fFNk8jGuNZgoCDLZw2RqrUd8FBFvN2wCRZXnS7Wg4QjiBdmnq0OsAwK9OFwqnil7DNnDnlytlecR5oYkDhO2fC4FzFiA==

For the same string, the .NET RSA Encryption method generates the following encrypted string with the same public key used by the Java program:

iJO4hwhXGX27jzK87X9gxzzbKpgf7FKhe6UcY7eoiCpLskOatgCMZTm0aTDuwRZGJGbZCIZt+JI9X8LxwOLmIbv5LGyDq+a8jkrPu+pDRvg2uRuKeQj2yBRcp36X+xFf61ux24NaX2RTCY9YfJcUis9NjEkL0eQ3gC79xO0vuBjaUA2oYOt0Mlr7DmKE+b0lz25J/WJuSW83g2oZOlvJ4RnsrFChu0vHnkHCQo9JVjhMc+Onj7+lbI1CDgGq4XigZrHt+j564y3sc3z0oQYfdZkF3yUZrzd3sJjd9KmryHf52eVb9/qgL2/Za1jUwTzKIOvtG/bQpR2ka7Qu1ZqbxQ==

But my .NET decryption method using the corresponding private key is able to decrypt both back to the same line of “Achinth Anand Gurkhi”. How is it possible that different encrypted strings return the same value?

+3
source share
4 answers

This may be due to random padding .

+7
source

Perhaps you were lucky about this and it was not bitten by it (perhaps because your sample file is only one block), but you need to make sure that the encryption mode is the same for both encryption and decryption.

In .NET, the encryption mode is controlled by the Modecipher property . In Java, it is controlled by the second and third parameter fieldstransformation Cipher.getInstance()

The default mode is also different between the two platforms (CBC in .NET, ECB in Java), which can disable you if you neglect the mode setting on both sides.

+1
source

, , , , . , . , , : , , .

+1

, :

. . .

Between the communication channel, one end (source) shares the public key with the other end (dest). Now the source encrypts its data with the private key and sends it to dest. Dest uses the public key for the source to decrypt it.

What could be here: the .NET and JAVA private keys are different, but the corresponding public keys must be inverse to the corresponding private keys.

These keys may take hostname / ip / or something (I'm not sure) to create a public / private key pair.
The public key encrytion needs two keys which are inverse of each other but not necessarily the encrypted data be same

Any comments / suggestions?

-1
source

All Articles