public void Decrypt_From_Client() { //Arrange string message = "message"; byte[] data = Encoding.UTF8.GetBytes(message); serviceMock.GenerateKey(); string PK = Keys.PublicKey; RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(PK); byte[] cipherbytes = rsa.Encrypt(data, false); //Act var plainbytes = serviceMock.RequestKey(cipherbytes); //Assert Assert.IsNotNull(plainbytes); Assert.IsInstanceOfType(plainbytes, typeof(string)); Assert.AreEqual(message, plainbytes); }
public void Encrypt_Decrypt() { //Arrange dynamic json = new JObject(); json.Data = "message"; //Act serviceRSAMock.GenerateKey(); var cipherbytes = serviceMock.Encrypt(json); var plainbytes = serviceMock.Decrypt(cipherbytes); //Assert Assert.IsNotNull(cipherbytes); Assert.AreEqual(Newtonsoft.Json.JsonConvert.SerializeObject(json), Newtonsoft.Json.JsonConvert.SerializeObject(plainbytes)); }