Why RSA encryption can return different results with C# and Java?

后端 未结 4 928
梦毁少年i
梦毁少年i 2021-01-14 03:39

I using:

  • c#: RSACryptoServiceProvider
  • JAVA: KeyFactory.getInstance(\"RSA\")+Cipher

I sending public key (exponent + mo

4条回答
  •  梦毁少年i
    2021-01-14 04:10

    i hope this is helpful , in C# lough code

                byte[] rsaExp = rsaParameters.Exponent.ToByteArray();
                byte[] Modulus = rsaParameters.Modulus.ToByteArray();
    
                // Microsoft RSAParameters modulo wants leading zero's removed so create new array with leading zero's removed
                int Pos = 0;
                for (int i = 0; i < Modulus.Length; i++)
                {
                    if (Modulus[i] == 0)
                    {
                        Pos++;
                    }
                    else
                    {
                        break;
                    }
                }
                byte[] rsaMod = new byte[Modulus.Length - Pos];
                Array.Copy(Modulus, Pos, rsaMod, 0, Modulus.Length - Pos);
    

提交回复
热议问题