Home > Net >  Ask a question about RSA encryption.
Ask a question about RSA encryption.

Time:01-12

Project using RSA encryption methods, front end use jsencrypt js for data encryption, the background using.net RSACryptoServiceProvider decryption
In general access is normal,
But occasionally encountered unexpected,
Such as encrypted using base64 encoded string at the end of the "==", cause I use ToBase64String string can be less a byte array, Decrypt method of directly using the rsa decryption tip when incorrect data, with the method of filling 0 at the end of, prompt parameter error,
There are some string directly prompt parameter errors, for example:
Results: after encryption YvMWrCKcdJaKqoXcVzOCHlwhZ12Vxd1 L8poDbF4F/NnUXARpjitS4W + Rj7UMFktWlPPOKy0neUo4HD77N0lTjrSZoRsSrMAdKAjfo4WV + 7 ju0hp9hloqduvva8grlngvaxmxnu/dm7RrL9MFYw17JR4wnqhuJd7h4PZlIPRRlA=
Public key:
-- -- -- -- -- BEGIN PUBLIC KEY -- -- -- -- --
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDz20w6LiltaFYwJhXlbUXlI/bq
NINYWe9EdUYuPnapqRmmHczq6cA1uceWANPf8ClYjbw2ABgXJw1TQ/ejAAHqXB8c
KKoAIodyudrlcERt17f31R/Tspkqr0p1SlNgiVE1a + QcMeNtzCi7ahshgR5 + 4 DKG
IKL91vDn55lO2INvkQIDAQAB
-- -- -- -- -- END PUBLIC KEY -- -- -- -- --
The private key:
-- -- -- -- -- BEGIN PRIVATE KEY -- -- -- -- --
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALLDg/93 xo7egqgn
I44ZMq47mGGXgpXmAAcImSZqGJZTmeiuGKfu7jqD7LFwSY + 4 u3ys8ka8qws1jdtl
VALmOvD1lf + uek7set4ajNbHHbLIq3cWgO056fo29eVTbtNZ8Eolfy + VmKcpCyZR
LYr5OneTtpRfro + 7 ogltmhn329elagmbaaecgybqqypekpkpme bnuA1QG/va3w3
77 exyExwn1v7zSqE3a jqq74mdgl + + NGJ55jde33B3PdchdjvvG4TRtWwjTTph0Bd
HC + yjdk5JAhxbnSNfIo3TdK2JD2UXbWWm6hMj9duFKrE9umXzuzRZ + ql/BFXxOtw
IjfjJZnfBK + jypBKWQJBAMQ3TL4P27j2vt5lSyAjHFTTR8EAjFqXYWtdFaZhGJVj
DSBModiQ76SyDLFjNOMNh0VXgFPy1XItQItPSOazNPMCQQDpOvN7bOFg7Dphf1Jr
JUvUnS1vcBdnRzp + ao2M06Y2IVez0j8r8nnVkhBc5lrpwbYRhacXXq69stI91OAO
HseHAkBqJTQ5uSB23dyBOLC8UOIZrTYq3V4P/8 zuqyt0fycsz8qjdgubuuq6hyta
PtdMYNwlkeFVCI + ZNYuuERTx4E4rAkBwXw7g8NzGLgsS3p1/MkEO94vknUUpZZAx
SHVa3L7AZeAzq6D0M6ev1ug7WmGDLuniF1siT2Qx0e6qC97IIPgRAkEAqb2O6sv +
FetkpaTGJ7fCNiiiQSe RWVD/cj + eO3qCqq61d0xg3ErMLEP/5 rnzs4pn0dcaqle
PPrrfEnbAAUIew==
PRIVATE KEY -- -- -- -- -- END -- -- -- -- --
Relevant code:
 
String t=@ "TxnwTeo7vP/hVBmKgQghngAxzvePoDDExY3liVRpiqvB0bt4qHvuswF2BALEXhH0O5p7LZmJUE1Fn/64 pvfgs1qznmg4vvvm + i0wSwfBCOUow7zDSHwnLGRgbNDbd2V7k796AG6rK0DICM4ySBf6x/v3g0z6Fyyww1Wi9NN8i4c=";
String u=@ "FsthrVnNuU231tA1AR31Rj4uliIYRFoVb0dQ4rRf7AkLP4vSm7nMNXmcmzVUXN2PkCsCD/QcH6BZ5BiQltJ5SvtZL4stK8mokKNeCcLBg4mNlN1PV005 + LXZy5Hx6LAvpwEXv + 90 ys1593oewi2 oyk8y7EL4 + D8e4hD3 + + Jf6rc=";
String c=@ "YvMWrCKcdJaKqoXcVzOCHlwhZ12Vxd1/L8poDbF4F/Rj7UMFktWlPPOKy0neUo4HD77N0lTjrSZoRsSrMAdKAjfo4WV NnUXARpjitS4W + + 7 ju0hp9hloqduvva8grlngvaxmxnu/dm7RrL9MFYw17JR4wnqhuJd7h4PZlIPRRlA=";
String p=@ "-- -- -- -- -- BEGIN PRIVATE KEY -- -- -- -- --
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALLDg/93 xo7egqgn
I44ZMq47mGGXgpXmAAcImSZqGJZTmeiuGKfu7jqD7LFwSY + 4 u3ys8ka8qws1jdtl
VALmOvD1lf + uek7set4ajNbHHbLIq3cWgO056fo29eVTbtNZ8Eolfy + VmKcpCyZR
LYr5OneTtpRfro + 7 ogltmhn329elagmbaaecgybqqypekpkpme bnuA1QG/va3w3
77 exyExwn1v7zSqE3a jqq74mdgl + + NGJ55jde33B3PdchdjvvG4TRtWwjTTph0Bd
HC + yjdk5JAhxbnSNfIo3TdK2JD2UXbWWm6hMj9duFKrE9umXzuzRZ + ql/BFXxOtw
IjfjJZnfBK + jypBKWQJBAMQ3TL4P27j2vt5lSyAjHFTTR8EAjFqXYWtdFaZhGJVj
DSBModiQ76SyDLFjNOMNh0VXgFPy1XItQItPSOazNPMCQQDpOvN7bOFg7Dphf1Jr
JUvUnS1vcBdnRzp + ao2M06Y2IVez0j8r8nnVkhBc5lrpwbYRhacXXq69stI91OAO
HseHAkBqJTQ5uSB23dyBOLC8UOIZrTYq3V4P/8 zuqyt0fycsz8qjdgubuuq6hyta
PtdMYNwlkeFVCI + ZNYuuERTx4E4rAkBwXw7g8NzGLgsS3p1/MkEO94vknUUpZZAx
SHVa3L7AZeAzq6D0M6ev1ug7WmGDLuniF1siT2Qx0e6qC97IIPgRAkEAqb2O6sv +
FetkpaTGJ7fCNiiiQSe RWVD/cj + eO3qCqq61d0xg3ErMLEP/5 rnzs4pn0dcaqle
PPrrfEnbAAUIew==
PRIVATE KEY -- -- -- -- -- END -- -- -- -- -- ";
String XMLS=@ "& lt; RSAKeyValue>
Aqsj3pKZD5hP257gNUBv72t8N + + yakO + DHRi/nschMcJ9b + 80 qhn2vjrieey3xt9wdz3xixy77xue0bvsi006ydaxyqvso3zosqicw50jxykn03stiq9lf21lpuoti/XbhSqxPbpl87s0WfqpfwRV8TrcIo34yWZ3wSvo8qQSlk=& lt;/D>
AiU0Obkgdt3cgTiwvFDiGa02Kt1eD//GbqsrdBcgkmfECQ4Lm7lEOocrQKbXTGDcJZHhVQiPmTWLrhEU8eBOKw==& lt;/DP>
CF8O4PDcxi4LEt6dfzJBDveL5J1FKWWQMUh1Wty + wGXgM6ug9DOnr9boO1phgy7p4hdbIk9kMdHuqgveyCD4EQ==& lt;/DQ>
AQAB
Qb2O6sv + FetkpaTGJ7fCNiiiQSe/RWVD/cj + eO3qCqq61d0xg3ErMLEP/5 rnzs4pn0dcaqlepprrfenbaauiew==& lt;/InverseQ>
Dc7sqzaaeljhkyrjuyyzecleyabwizjmoylloz6k4yp ssOD/3 + 7 uoopssxbjj7htdhlwodxdblwn20tuauy68pwv/656 tux63hqm1scdssirdxaa7tnp + jb15VNu01nwSiV L5WYpykLJlEtivk6d5O2lF + uj7s6CW2aGffb0SU=& lt;/Modulus>

XDdMvg ritain + 3 mvlicmcvnnhwqcmwpdha10vpmeylwmnieyh2jdvplimswm04w2hrveau/LVci1Ai09I5rM08w==& lt;/P>
6 trze2zhyow6yx9sayvl1j0tb3axz0c6fmqnjnomnifxs9i/K/J51ZIQXOZa6cG2EYWnF16uvbLSPdTgDobHhw==& lt;/Q>
";
Byte [] by=the Convert. FromBase64String (c);
Response. Write (DAL. RSA_Decode. DecodeOrNull (c). The Str);
//Response. Write (b.L ength);
Response. Write (c);
Response. Write (" & lt; Br/& gt;" );
Response. Write (Convert. ToBase64String (by));
Response. Write (" & lt; Br/& gt;" );
Response. Write (by. Length. The ToString ());
Response. Write (" & lt; Br/& gt;" );
Response. Write (RSADecrypt (XMLS, c));


 
Public string RSADecrypt (string xmlPrivateKey, string decryptString)
{
Try
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related