C
C
Ckpyt2016-03-11 20:43:28
C++ / C#
Ckpyt, 2016-03-11 20:43:28

How to decrypt RSA without having the public key?

Task: The server transmits the private key and ciphertext. We need to decrypt it.
I see in .NET there is a RSACryptoServiceProvider class.
BUT! This dog requires a public key. Those. exhibitors. I read about RSA, tried to slip a secret exponent instead of an exponent, writes bad data ...
Maybe someone can tell me the RSA library or how to work with .NET to solve this problem?
P.s. transferring the public key together with the private key is not an option - on the other side they must be able to decrypt, but not be able to encrypt.
P.p.s test piece of code:

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(1024);
                String str = rsa.ToXmlString(true);

                MemoryStream config = new MemoryStream();
                BinaryFormatter serial = new BinaryFormatter();
                serial.Serialize(config, str.ToArray());

                byte[] serialObj = config.ToArray();

                
                string RSAKey = "<RSAKeyValue><Modulus>rZfC4KXnycP+MyK7Z94VEurnIkU9+3RoTo8gv1CfNDwdIEGnk9oTWUmScy7cscTYXOyDAGl7L+qFq+0gkf6Y4ssNEbyYIxSpfGuzIHLUYbmm1EWPGSOsADmNGZPB0zK9MIP3+q9Jm766lrlGMs3EwvIm3eaeN2RzqSbQGaE85LM=</Modulus><Exponent>AQAB</Exponent><P>vqjQLNlT+FpCpoCU97DtIJlxg8Zg+8tqmo70nFPw5AWIP4eTDaAVheJ/iCQe9JfT8oId4kJ7vVy1ZBPhZtNQew==</P><Q>6RWjN2gz7Sdjwdk71kJ7JVqpeAlqm3hR1o9DXvHluEWsWPaqqt/2a3G0EnX6q+ToBAO37mjLtqvWFF8gf62zKQ==</Q><DP>JCNPQhD3b418MJ8SnVg1ugYblASYAWHvFNif2Lm4YSADUTdbUivTqIrj7WQbUfUtQTwUefxsA9p8rzltcdX/3Q==</DP><DQ>VyVO4+1i1L1Qb+6/j4lFr56pFAc5Q62Fs5nWz43TnMT3/j8jakXYRS267NgNg+1Ozglx4IJv//lZTj6O0Q3pmQ==</DQ><InverseQ>cTBRRTeFvCuQqUk41gqbZaYBvkvSxOsOYC/2947c4Rrew6Gzokxo2hStOajpEZq+ZNd9qr8Cqkce6WQGqGMBpQ==</InverseQ><D>G1z5PIUaWN0apD/cz54br0w029uTTiBG0t9P16hjOA4jvzJqMm2lMCVfPuXLpv/y5Q7pBXcbEm4C3Rt3T1wVCCQTH/WnzTVtL5h+iwXf6qJYsUlVLOmtg8XD6K6rGKE0XXP8UBOMqSzE72nl0eAn4uXmN8qR7U117QtPpE5skCk=</D></RSAKeyValue>";
                string RSAEncrKey = "<RSAKeyValue><Modulus>rZfC4KXnycP+MyK7Z94VEurnIkU9+3RoTo8gv1CfNDwdIEGnk9oTWUmScy7cscTYXOyDAGl7L+qFq+0gkf6Y4ssNEbyYIxSpfGuzIHLUYbmm1EWPGSOsADmNGZPB0zK9MIP3+q9Jm766lrlGMs3EwvIm3eaeN2RzqSbQGaE85LM=</Modulus><Exponent>G1z5PIUaWN0apD/cz54br0w029uTTiBG0t9P16hjOA4jvzJqMm2lMCVfPuXLpv/y5Q7pBXcbEm4C3Rt3T1wVCCQTH/WnzTVtL5h+iwXf6qJYsUlVLOmtg8XD6K6rGKE0XXP8UBOMqSzE72nl0eAn4uXmN8qR7U117QtPpE5skCk=</Exponent></RSAKeyValue>";
                string RSADecrKey = "<RSAKeyValue><Modulus>rZfC4KXnycP+MyK7Z94VEurnIkU9+3RoTo8gv1CfNDwdIEGnk9oTWUmScy7cscTYXOyDAGl7L+qFq+0gkf6Y4ssNEbyYIxSpfGuzIHLUYbmm1EWPGSOsADmNGZPB0zK9MIP3+q9Jm766lrlGMs3EwvIm3eaeN2RzqSbQGaE85LM=</Modulus><Exponent>AQAB</Exponent><P>vqjQLNlT+FpCpoCU97DtIJlxg8Zg+8tqmo70nFPw5AWIP4eTDaAVheJ/iCQe9JfT8oId4kJ7vVy1ZBPhZtNQew==</P><Q>6RWjN2gz7Sdjwdk71kJ7JVqpeAlqm3hR1o9DXvHluEWsWPaqqt/2a3G0EnX6q+ToBAO37mjLtqvWFF8gf62zKQ==</Q><DP>JCNPQhD3b418MJ8SnVg1ugYblASYAWHvFNif2Lm4YSADUTdbUivTqIrj7WQbUfUtQTwUefxsA9p8rzltcdX/3Q==</DP><DQ>VyVO4+1i1L1Qb+6/j4lFr56pFAc5Q62Fs5nWz43TnMT3/j8jakXYRS267NgNg+1Ozglx4IJv//lZTj6O0Q3pmQ==</DQ><InverseQ>cTBRRTeFvCuQqUk41gqbZaYBvkvSxOsOYC/2947c4Rrew6Gzokxo2hStOajpEZq+ZNd9qr8Cqkce6WQGqGMBpQ==</InverseQ><D>G1z5PIUaWN0apD/cz54br0w029uTTiBG0t9P16hjOA4jvzJqMm2lMCVfPuXLpv/y5Q7pBXcbEm4C3Rt3T1wVCCQTH/WnzTVtL5h+iwXf6qJYsUlVLOmtg8XD6K6rGKE0XXP8UBOMqSzE72nl0eAn4uXmN8qR7U117QtPpE5skCk=</D></RSAKeyValue>";
                RSACryptoServiceProvider rsaEncr = new RSACryptoServiceProvider();
                rsaEncr.FromXmlString(RSAEncrKey);

                byte[] fst = new byte[60];

                for (int i = 0; i < fst.Length; i++)
                    fst[i] = serialObj[i];
                byte[] encr = rsa.Encrypt(fst, false);

                rsa.FromXmlString(RSADecrKey);
                byte[] decr = rsa.Encrypt(encr, false);

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
Ckpyt, 2016-03-11
@Ckpyt

The problem is solved through the BigInteger.ModPow() method;
Thank you all for your input, I'll close the question.
P.s. export to RSAParameters has reverse byte order compared to BigInteger import

E
evnuh, 2016-03-11
@evnuh

That is, you transmit a ciphertext and a private key over an insecure channel?) But at the same time you are afraid to transmit a public key?)) Why is such encryption necessary if you transmit the key next to the cipher?
And yes, RSACryptoProvider for decryption requires absolutely all the same values ​​that were used when generating keys.

V
Vyacheslav Zolotov, 2016-03-11
@SZolotov

You have the wrong algorithm. The client must generate a pair of keys, then he sends the public key to the server, with which everything is encrypted

M
mayorovp, 2016-03-13
@mayorovp

I'll add my answer to Habré here.
https://habrahabr.ru/post/279093/#comment_8803859

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question