c# - CryptographicEngine Decrypt throw Value does not fall within the expected range exception in Decrypt mathod -


i try use code value not fall within expected range exception in decrypt mathod when decrypt line happen

this singleton class create key once

{     public class cryptographyprovider     {         private cryptographickey key;         public cryptographyprovider()         {             string asymmetricalgname = windows.security.cryptography.core.asymmetricalgorithmnames.rsapkcs1;             asymmetrickeyalgorithmprovider asym = asymmetrickeyalgorithmprovider.openalgorithm(asymmetricalgname);              key = asym.createkeypair(512);          }         public string encrypt(string source)         {             ibuffer buf = cryptographicbuffer.convertstringtobinary(source, binarystringencoding.utf16be);             ibuffer enc = cryptographicengine.encrypt(key, buf, null);             byte[] encryptedbytearr;             cryptographicbuffer.copytobytearray(enc, out encryptedbytearr);             var ret =  convert.tobase64string(encryptedbytearr);              return ret;         }          public string decrypt(string source)         {             ibuffer buf = cryptographicbuffer.convertstringtobinary(source, binarystringencoding.utf16be);             ibuffer enc = cryptographicengine.decrypt(key, buf, null);             byte[] encryptedbytearr;             cryptographicbuffer.copytobytearray(enc, out encryptedbytearr);             var ret = convert.tobase64string(encryptedbytearr);             return ret;         }     } } 

what wrong in code?


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -