コード例 #1
0
        public void EncryptJsonAsyncThrowsWhenCryptoIsNull()
        {
            var json          = "{\"foo\":\"abc\",\"bar\":123,\"baz\":true,\"qux\":[1,2,3],\"garply\":{\"grault\":\"xyz\"},\"fred\":null}";
            var keyIdentifier = new object();

            ICrypto crypto = null;

            Assert.That(async() => await crypto.EncryptJsonAsync(json, new[] { "$.foo", "$.bar", "$.baz", "$.qux", "$.garply", "$.fred" }, keyIdentifier), Throws.ArgumentNullException);
        }
コード例 #2
0
 /// <summary>
 /// Asynchronously encrypts the fields, specified by JSONPath, that are contained in the given json document string.
 /// </summary>
 /// <param name="crypto">
 /// The instance of <see cref="ICrypto"/> that ultimately responsible for performing encryption operations
 /// on field values.
 /// </param>
 /// <param name="jsonString">A string containing an json document.</param>
 /// <param name="jsonPathToEncrypt">The JSONPath of the field to encrypt.</param>
 /// <param name="credentialName">
 /// The name of the credential to use for this encryption operation,
 /// or null to use the default credential.
 /// </param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task that will contain the same json document, except with the specified fields encrypted.</returns>
 public static Task <string> EncryptJsonAsync(this ICrypto crypto, string jsonString, string jsonPathToEncrypt, string credentialName = null, CancellationToken cancellationToken = default(CancellationToken)) =>
 crypto.EncryptJsonAsync(jsonString, new[] { jsonPathToEncrypt }, credentialName, cancellationToken);