Java RSA Encrypt - Decrypt .NET

后端 未结 1 2009
囚心锁ツ
囚心锁ツ 2020-12-30 09:45

I am encrypting on JAVA using RSA and attempting to decrypt using .NET. I am including my JAVA code and .NET code in hopes that someone has some experience with this sort o

相关标签:
1条回答
  • 2020-12-30 10:20

    On the Java side, you need to use "RSA/ECB/PKCS1Padding" as algorithm name. With the plain "RSA" name, Java does not add the PKCS#1 padding which the C# implementation expects, hence the "bad data".

    The padding is a transformation of the input data (your encoded string) into a somewhat larger string which has the same length than the RSA modulus (128 bytes here). It is important for security and injects some randomness (the same input string will not yield the same encrypted string every time; but the decryption process removes that randomness and recovers the right string nonetheless).

    0 讨论(0)
提交回复
热议问题