public override DecryptResult Decrypt(DecryptParameters parameters, CancellationToken cancellationToken) { Argument.AssertNotNull(parameters, nameof(parameters)); if (MustRemote) { // A private key is required to decrypt. Send to the server. KeysEventSource.Singleton.PrivateKeyRequired(nameof(Decrypt)); return(null); } EncryptionAlgorithm algorithm = parameters.Algorithm; RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding(); if (padding is null) { KeysEventSource.Singleton.AlgorithmNotSupported(nameof(Decrypt), algorithm); return(null); } byte[] plaintext = Decrypt(parameters.Ciphertext, padding); DecryptResult result = null; if (plaintext != null) { result = new DecryptResult { Algorithm = algorithm, KeyId = KeyMaterial.Id, Plaintext = plaintext, }; } return(result); }
public override EncryptResult Encrypt(EncryptParameters parameters, CancellationToken cancellationToken) { Argument.AssertNotNull(parameters, nameof(parameters)); ThrowIfTimeInvalid(); EncryptionAlgorithm algorithm = parameters.Algorithm; RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding(); if (padding is null) { KeysEventSource.Singleton.AlgorithmNotSupported(nameof(Encrypt), algorithm); return(null); } byte[] ciphertext = Encrypt(parameters.Plaintext, padding); EncryptResult result = null; if (ciphertext != null) { result = new EncryptResult { Algorithm = algorithm, Ciphertext = ciphertext, KeyId = KeyMaterial.Id, }; } return(result); }
public DecryptResult Decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv, byte[] authenticationData, byte[] authenticationTag, CancellationToken cancellationToken) { Argument.AssertNotNull(ciphertext, nameof(ciphertext)); RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding(); byte[] plaintext = Decrypt(ciphertext, padding); return(new DecryptResult { Algorithm = algorithm, KeyId = _jwk.KeyId, Plaintext = plaintext, }); }
public override DecryptResult Decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken) { Argument.AssertNotNull(ciphertext, nameof(ciphertext)); RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding(); byte[] plaintext = Decrypt(ciphertext, padding); DecryptResult result = null; if (plaintext != null) { result = new DecryptResult { Algorithm = algorithm, KeyId = KeyMaterial.Id, Plaintext = plaintext, }; } return(result); }
public EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv, byte[] authenticationData, CancellationToken cancellationToken) { Argument.AssertNotNull(plaintext, nameof(plaintext)); RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding(); byte[] ciphertext = Encrypt(plaintext, padding); EncryptResult result = null; if (ciphertext != null) { result = new EncryptResult { Algorithm = algorithm, Ciphertext = ciphertext, KeyId = _jwk.Id, }; } return(result); }
public override EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken) { Argument.AssertNotNull(plaintext, nameof(plaintext)); ThrowIfTimeInvalid(); RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding(); byte[] ciphertext = Encrypt(plaintext, padding); EncryptResult result = null; if (ciphertext != null) { result = new EncryptResult { Algorithm = algorithm, Ciphertext = ciphertext, KeyId = KeyMaterial.Id, }; } return(result); }