Why is RSAParameters Modulus not equal product of P and Q?

前端 未结 2 944
说谎
说谎 2020-12-16 02:29

The values of P and Q do not match value of the Modulus of the .Net RSAParameters. According to RSA algorithm and MSDN documentation it should be: P * Q = Modulus

I

相关标签:
2条回答
  • 2020-12-16 02:58

    Here is my parsing of the XML parameters you provided:

    N = 9100595563660672087698322262735024483609782000266155222822537546670463733453350686171384417480667378838400923087358115007100900745853538273602044437940579
    
    P = 96731388413554317303099785843734797692955743043844132225634400270674214374921
    
    Q = 94081101418218318334927154927633016498744568046568114230258529096538660255499
    

    As you can verify, N does indeed equal P * Q.

    You cannot use the BigInteger(byte []) constructor the way you are because it expects the byte array to be in little-endian, and because Microsoft has done things bass ackwards. Instead, reverse the order of the bytes. And finally, because the bytes arrays are supposed to be twos complement and your numbers are guaranteed to be positive you must add a zero byte to the high order byte of the array if the high-order byte would otherwise be greater than or equal to 128.

    0 讨论(0)
  • 2020-12-16 02:58

    BigInteger parses arrays as signed little-endian values. RSAParameters uses unsigned big-endian.

    So i = new BigInteger(bytes.Reverse().Concat(new byte[]{0}).ToArray())) should work.

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