From 36e5661c82331907b08374629f769257b8e3ed61 Mon Sep 17 00:00:00 2001 From: Vladimir Shchur Date: Thu, 4 Jul 2024 17:09:39 +0300 Subject: [PATCH] Added RSA disposal --- src/Pulsar.Client/Crypto/MessageCrypto.fs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Pulsar.Client/Crypto/MessageCrypto.fs b/src/Pulsar.Client/Crypto/MessageCrypto.fs index 87026064..450e72cf 100644 --- a/src/Pulsar.Client/Crypto/MessageCrypto.fs +++ b/src/Pulsar.Client/Crypto/MessageCrypto.fs @@ -36,8 +36,7 @@ type MessageEncryptor(keyNames: string seq, keyReader: ICryptoKeyReader) = let loadPublicKey keyName = let publicKeyInfo = keyReader.GetPublicKey keyName let rsaPublicKey = parsePublicKey publicKeyInfo.Key - let rsa = RSA.Create() - rsa.ImportParameters rsaPublicKey + use rsa = RSA.Create(rsaPublicKey) let encKey = rsa.Encrypt(symmetricKey.Export(KeyBlobFormat.RawSymmetricKey), RSAEncryptionPadding.OaepSHA1) let encryptionKeys = EncryptionKey(keyName, encKey, publicKeyInfo.Metadata) encryptionKeys @@ -82,8 +81,7 @@ type MessageDecryptor(keyReader: ICryptoKeyReader) = try let privateKey = keyReader.GetPrivateKey(encryptionKey.Name, encryptionKey.Metadata) let rsaPrivateKey = parsePrivateKey privateKey.Key - let rsa = RSA.Create() - rsa.ImportParameters(rsaPrivateKey) + use rsa = RSA.Create(rsaPrivateKey) let keyBlob = rsa.Decrypt(encKey, RSAEncryptionPadding.OaepSHA1) Some(encKey, keyBlob) with ex ->