Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc中使用公钥的2048 RSA数据加密算法_Asp.net_Asp.net Mvc_Asp.net Mvc 4_Asp.net Mvc 3_Asp.net Web Api - Fatal编程技术网

Asp.net mvc中使用公钥的2048 RSA数据加密算法

Asp.net mvc中使用公钥的2048 RSA数据加密算法,asp.net,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-3,asp.net-web-api,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Asp.net Mvc 3,Asp.net Web Api,我想加密一个json数据 { “urc”:“7718313198”, “联电”:“101871”, “ak”:“asdfgh123456”, “fname”:“Biswajit”, “lname”:“Dolui”, “电子邮件”:retailer001@giblvirtualmail.com", “phno”:“7718313198”, “pin”:“712410” }我无法使用rsa算法2048加密asp.net中的长字符串 var csp=新的RSA加密服务提供商(2048) 欢迎来到Sta

我想加密一个json数据 { “urc”:“7718313198”, “联电”:“101871”, “ak”:“asdfgh123456”, “fname”:“Biswajit”, “lname”:“Dolui”, “电子邮件”:retailer001@giblvirtualmail.com", “phno”:“7718313198”, “pin”:“712410”
}

我无法使用rsa算法2048加密asp.net中的长字符串 var csp=新的RSA加密服务提供商(2048)


欢迎来到Stackoverflow。请注意,SO不是代码编写服务。请编辑您的问题并添加您目前编写的代码,谢谢。//应用pkcs#1.5填充并加密我们的数据var bytesCypherText=csp.encrypt(bytesplantextdata,false);这里我看到了问题,当我传递小字符串进行加密时,它是可以的,但是当我传递长字符串进行加密时,它就没有被加密。
        //how to get the private key
        var privKey = csp.ExportParameters(true);

        //and the public key ...
        var pubKey = csp.ExportParameters(false);

        //converting the public key into a string representation
        string pubKeyString;
        {
            //we need some buffer
            var sw = new System.IO.StringWriter();
            //we need a serializer
            var xs = new System.Xml.Serialization.XmlSerializer(typeof(RSAParameters));
            //serialize the key into the stream
            xs.Serialize(sw, pubKey);
            //get the string from the stream
            pubKeyString = sw.ToString();
        }

        //converting it back
        {
            //get a stream from the string
            var sr = new System.IO.StringReader(pubKeyString);
            //we need a deserializer
            var xs = new System.Xml.Serialization.XmlSerializer(typeof(RSAParameters));
            //get the object back from the stream
            pubKey = (RSAParameters)xs.Deserialize(sr);
        }

        //conversion for the private key is no black magic either ... omitted

        //we have a public key ... let's get a new csp and load that key
        csp = new RSACryptoServiceProvider();
        csp.ImportParameters(pubKey);

        //we need some data to encrypt
        var plainTextData = "{urc: 7718313198,umc: 101871,ak: asdfgh123456,fname: Biswajit,lname: Dolui,email: biswajitdoluicse@gmail.com,phno: 7718313198}";

        //for encryption, always handle bytes...
        var bytesPlainTextData = System.Text.Encoding.Unicode.GetBytes(plainTextData);

        //apply pkcs#1.5 padding and encrypt our data 
        var bytesCypherText = csp.Encrypt(bytesPlainTextData, false);

        //we might want a string representation of our cypher text... base64 will do
        var cypherText = Convert.ToBase64String(bytesCypherText);