private static async Task <T> GetAndVerifySignedDataAsync <T>(string signedDataJson) where T : class { var signedData = await JsonUtils.DeserializeAsync <SignedData>(signedDataJson); var dataJson = Config.DefaultEncoding.GetString(signedData.Data); var baseModel = await JsonUtils.DeserializeAsync <BaseModel>(dataJson); if (baseModel?.Sender?.PublicKey == null) { return(null); } AsymmetricKeyParameter publicKey; try { var publicKeyPem = baseModel.Sender.PublicKey.Replace("RSA PUBLIC KEY", "PUBLIC KEY"); publicKey = PemUtils.GetKeyFromPem(publicKeyPem); } catch (ArgumentException) { return(null); } var dataToVerify = Config.DefaultEncoding.GetBytes(Convert.ToBase64String(signedData.Data)); var isValid = SignUtils.Verify(dataToVerify, signedData.Signature, publicKey); if (!isValid) { return(null); } var text = Config.DefaultEncoding.GetString(signedData.Data); var model = await JsonUtils.DeserializeAsync <T>(text); return(model); }