Example #1
0
        private JObject GetEncryptedJObject(string json)
        {
            var jObject   = JObjectTools.GetJObject(json);
            var publicKey = GetPublicKey(jObject);

            _jObjectCrypto.Encrypt(jObject, publicKey);

            return(jObject);
        }
Example #2
0
        private JObject GetDecryptJObject(string json, IPrivateKeyProvider keyProvider)
        {
            var jObject   = JObjectTools.GetJObject(json);
            var publicKey = GetPublicKey(jObject);

            keyProvider = keyProvider ?? new DefaultPrivateKeyProvider();
            if (keyProvider.TryGetPrivateKey(publicKey, out string privateKey))
            {
                _jObjectCrypto.Decrypt(jObject, privateKey);
                return(jObject);
            }

            throw new InvalidOperationException($"Could not find private key for: {publicKey}");
        }