public static string getEncryptedMessage(string msg, RSAKeyValue key)
        {
            string[] segments          = getSegments(msg);
            string[] encryptedSegments = new string[segments.Length];

            for (int i = 0; i < segments.Length; i++)
            {
                encryptedSegments[i] = Convert.ToBase64String(RSAEncrypt(Encoding.UTF8.GetBytes(segments[i]), key));
            }

            string JSON = JSONManager.serialize(encryptedSegments);

            return(JSON);
        }
        public static string getPublicKey()
        {
            CspParameters param = new CspParameters();

            param.KeyContainerName = "VC_RSA_KEY";
            //Create a new instance of RSACryptoServiceProvider.
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048, param))
            {
                string      xmlKey = RSA.ToXmlString(false);
                RSAKeyValue key    = XMLManager.deserialize <RSAKeyValue>(xmlKey);
                Console.WriteLine("MOD:" + Convert.FromBase64String(key.Modulus).Length *8);
                string jsonKey = JSONManager.serialize(key);

                return(jsonKey);
            }
        }
        public static byte[] RSAEncrypt(byte[] toEncrypt, RSAKeyValue key)
        {
            byte[] encrypted;

            RSAParameters parameters = new RSAParameters();

            parameters.Modulus  = Convert.FromBase64String(key.Modulus);
            parameters.Exponent = Convert.FromBase64String(key.Exponent);

            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048))
            {
                try
                {
                    RSA.ImportParameters(parameters);
                    encrypted = RSA.Encrypt(toEncrypt, true);
                }
                finally
                {
                    RSA.PersistKeyInCsp = false;
                }
            }

            return(encrypted);
        }