public void DecryptOperationNotSupported() { JsonWebKey jwk = new JsonWebKey(RSA.Create(), keyOps: Array.Empty <KeyOperation>()); LocalCryptographyClient client = CreateClient <LocalCryptographyClient>(jwk); Assert.ThrowsAsync <NotSupportedException>(async() => await client.DecryptAsync(new EncryptionAlgorithm("ignored"), TestData)); }
public void AesDecryptAlgorithmNotSupported([EnumValues(nameof(EncryptionAlgorithm.A128Gcm), nameof(EncryptionAlgorithm.A192Gcm), nameof(EncryptionAlgorithm.A256Gcm))] EncryptionAlgorithm algorithm) { JsonWebKey jwk = CreateKey(KeyType.Oct); LocalCryptographyClient client = CreateClient <LocalCryptographyClient>(jwk); Assert.ThrowsAsync <NotSupportedException>(async() => await client.DecryptAsync(algorithm, TestData)); }
public void DecryptAlgorithmNotSupported([EnumValues(Exclude = new[] { nameof(KeyType.Rsa), nameof(KeyType.RsaHsm), nameof(KeyType.Oct), nameof(KeyType.OctHsm) })] KeyType keyType) { JsonWebKey jwk = CreateKey(keyType); LocalCryptographyClient client = CreateClient <LocalCryptographyClient>(jwk); Assert.ThrowsAsync <NotSupportedException>(async() => await client.DecryptAsync(new EncryptionAlgorithm("ignored"), TestData)); }
public async Task EncryptDecryptRoundtrip([EnumValues(nameof(EncryptionAlgorithm.Rsa15), nameof(EncryptionAlgorithm.RsaOaep))] EncryptionAlgorithm algorithm) { JsonWebKey jwk = CreateKey(KeyType.Rsa, includePrivateParameters: true); LocalCryptographyClient client = CreateClient <LocalCryptographyClient>(jwk); EncryptResult encrypted = await client.EncryptAsync(algorithm, TestData); DecryptResult decrypted = await client.DecryptAsync(algorithm, encrypted.Ciphertext); string actual = Encoding.UTF8.GetString(decrypted.Plaintext); Assert.AreEqual("test", actual); }
public async Task DecryptRequiresPrivateKey() { JsonWebKey jwk = CreateKey(KeyType.Rsa, keyOps: new[] { KeyOperation.Encrypt, KeyOperation.Decrypt }); LocalCryptographyClient client = CreateClient <LocalCryptographyClient>(jwk); EncryptResult encrypted = await client.EncryptAsync(EncryptionAlgorithm.RsaOaep, TestData); Assert.ThrowsAsync(new InstanceOfTypeConstraint(typeof(CryptographicException)), async() => await client.DecryptAsync(EncryptionAlgorithm.RsaOaep, encrypted.Ciphertext)); }