private void EncryptDecrypt (string msg, RSAManaged rsa) { RSAParameters param = rsa.ExportParameters (false); byte[] data = { 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 }; // we don't need the private key to encrypt RSAManaged pubkey = new RSAManaged (); pubkey.ImportParameters (param); byte[] enc = pubkey.EncryptValue (data); byte[] dec = rsa.DecryptValue (enc); // note: the decrypted value is now right padded with zeros Assert.IsTrue (BitConverter.ToString (dec).EndsWith (BitConverter.ToString (data)), msg); }
public void Bug79269 () { RSAManaged rsa = new RSAManaged (); rsa.FromXmlString ("<RSAKeyValue><Modulus>iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=</Modulus><Exponent>EQ==</Exponent></RSAKeyValue>"); Assert.IsTrue (rsa.PublicOnly, "PublicOnly"); string b64 = @"YgyAhscnTTIcDeLJTZcOYYyHVxNhV6d03jeZYjq0sPMEsfCCbE/NcFyYHD9BTuiduqPplCLbGpfZIZYJ6vAP9m5z4Q9eEw79kmEFCsm8wSKEo/gKiptVpwQ78VOPrWd/wEkTTeeg2nVim3JIsTKGFlV7rKxIWQhGN9aAqgP8nZI="; byte [] bytes = Convert.FromBase64String (b64); rsa.DecryptValue (bytes); }
private void EncryptDecrypt (string msg, RSAManaged rsa) { RSAParameters param = rsa.ExportParameters (false); byte[] data = { 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 }; // we don't need the private key to encrypt RSAManaged pubkey = new RSAManaged (); pubkey.ImportParameters (param); byte[] enc = pubkey.EncryptValue (data); byte[] dec = rsa.DecryptValue (enc); Assert.AreEqual (BitConverter.ToString (data), BitConverter.ToString (dec), msg); }