Asymetric Encryption (Encrypt in Javascript and Decrypt in C#) with RSA,etc. RRS feed

  • Question

  • Hello ,i am working in a proyect about asymetric encryption.I need to encrypt the information of my web page and I need an example of an asymetric encryption in c#.It is necesary that encrypt will be in Javascript  and decrypt will be in C#.

    Wednesday, August 21, 2019 9:12 AM

All replies

  • Most of the algorithms you're likely to encounter are asymmetric.  You just need to find a crypto scheme that's available in your Javascript environment.  The C# cryptography stuff starts here:

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Wednesday, August 21, 2019 5:10 PM
  • Hi MarioVIGO7, 

    Thank you for posting here.

    For your question, I make a sample about RSA Encrypt and Decrypt in C#.


            static void Main(string[] args)
                    ASCIIEncoding ByteConverter = new ASCIIEncoding();
                    string dataString = "Data to Encrypt";
                    byte[] dataToEncrypt = ByteConverter.GetBytes(dataString);
                    byte[] encryptedData;
                    byte[] decryptedData;
                    RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider();
                    Console.WriteLine($"Original Data: {dataString}");
                    encryptedData = RSAalg.Encrypt(dataToEncrypt, false);
                    Console.WriteLine($"Encrypted Data: {ByteConverter.GetString(encryptedData)}");
                    decryptedData = RSAalg.Decrypt(encryptedData, false);
                    Console.WriteLine($"Decrypted plaintext: {ByteConverter.GetString(decryptedData)}");
                catch (CryptographicException e)


    Besides, if you want to know how to Encrypt data in JavaScript, I suggest you ask in JavaScript forums. The C# forum is for C# related question.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, August 22, 2019 5:45 AM