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
Post a Comment