PostSolvedRSA encrypting and decrypting

Posts 15 of 5 · Page 1 of 1
RSA encrypting and decrypting
Hey! I'm trying to make a function that takes a public key and text to format as parameters, both as strings. I'm trying to log in to steam via post requests and have to pass in the password encrypted with RSA key gotten from steam. I can get the key from steam fine as string but I cannot find a working way to use the key to encrypt the password.
I haven't worked yet with RSA. The concept seems to be interesting though. So. After googleing it, I guess, this is what you are looking for:
Code:
public static string Encryption(string strText)
        {
            var publicKey = "<RSAKeyValue><Modulus>21wEnTU+mcD2w0Lfo1Gv4rtcSWsQJQTNa6gio05AOkV/Er9w3Y13Ddo5wGtjJ19402S71HUeN0vbKILLJdRSES5MHSdJPSVrOqdrll/vLXxDxWs/U0UT1c8u6k/Ogx9hTtZxYwoeYqdhDblof3E75d9n2F0Zvf6iTb4cI7j6fMs=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

            var testData = Encoding.UTF8.GetBytes(strText);

            using (var rsa = new RSACryptoServiceProvider(1024))
            {
                try
                {
                    // client encrypting data with public key issued by server                    
                    rsa.FromXmlString(publicKey.ToString());

                    var encryptedData = rsa.Encrypt(testData, true);

                    var base64Encrypted = Convert.ToBase64String(encryptedData);

                    return base64Encrypted;
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
        }


Source: https://stackoverflow.com/questions/17128038/c-sharp-rsa-encryption-decryption-with-transmission
Quote Originally Posted by defaulto View Post
I haven't worked yet with RSA. The concept seems to be interesting though. So. After googleing it, I guess, this is what you are looking for:
Code:
public static string Encryption(string strText)
        {
            var publicKey = "<RSAKeyValue><Modulus>21wEnTU+mcD2w0Lfo1Gv4rtcSWsQJQTNa6gio05AOkV/Er9w3Y13Ddo5wGtjJ19402S71HUeN0vbKILLJdRSES5MHSdJPSVrOqdrll/vLXxDxWs/U0UT1c8u6k/Ogx9hTtZxYwoeYqdhDblof3E75d9n2F0Zvf6iTb4cI7j6fMs=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

            var testData = Encoding.UTF8.GetBytes(strText);

            using (var rsa = new RSACryptoServiceProvider(1024))
            {
                try
                {
                    // client encrypting data with public key issued by server                    
                    rsa.FromXmlString(publicKey.ToString());

                    var encryptedData = rsa.Encrypt(testData, true);

                    var base64Encrypted = Convert.ToBase64String(encryptedData);

                    return base64Encrypted;
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
        }


Source: https://stackoverflow.com/questions/17128038/c-sharp-rsa-encryption-decryption-with-transmission
It's giving me some errors:

x64: Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
x86: Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'C:\Users\makez\source\repos\RSA\RSA\bin\x86\Relea se\netcoreapp2.1\RSA.dll'. An attempt was made to load a program with an incorrect format.

(In build settings application type is set to console application)
Quote Originally Posted by JustWorkHereLUL View Post
It's giving me some errors:

x64: Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
x86: Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'C:\Users\makez\source\repos\RSA\RSA\bin\x86\Relea se\netcoreapp2.1\RSA.dll'. An attempt was made to load a program with an incorrect format.

(In build settings application type is set to console application)
Wait I give it a try myself. Will edit this reply when I got it working.
Did you downloaded something extra? It should be already included in the .NET Framework, which can be used by "using System.Security.Cryptography;".
Is NET Core actually the same as the NET Framework?
Quote Originally Posted by defaulto View Post
Is NET Core actually the same as the NET Framework?
Ah damn I accidently had made .NET Core console application instead of .NET Framework, works now!
Posts 15 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?