diff options
Diffstat (limited to 'crypto/src/crmf')
-rw-r--r-- | crypto/src/crmf/EncryptedValueBuilder.cs | 8 | ||||
-rw-r--r-- | crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs | 10 |
2 files changed, 11 insertions, 7 deletions
diff --git a/crypto/src/crmf/EncryptedValueBuilder.cs b/crypto/src/crmf/EncryptedValueBuilder.cs index 0154be58c..37f38df1c 100644 --- a/crypto/src/crmf/EncryptedValueBuilder.cs +++ b/crypto/src/crmf/EncryptedValueBuilder.cs @@ -112,12 +112,14 @@ namespace Org.BouncyCastle.Crmf private EncryptedValue EncryptData(byte[] data) { MemoryOutputStream bOut = new MemoryOutputStream(); - Stream eOut = encryptor.BuildCipher(bOut).Stream; + var cipher = encryptor.BuildCipher(bOut); try { - eOut.Write(data, 0, data.Length); - Platform.Dispose(eOut); + using (var eOut = cipher.Stream) + { + eOut.Write(data, 0, data.Length); + } } catch (IOException e) { diff --git a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs index eed66b083..4cd568e81 100644 --- a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs +++ b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs @@ -38,11 +38,13 @@ namespace Org.BouncyCastle.Crmf { IMacFactory fact = generator.Build(password); - IStreamCalculator<IBlockResult> calc = fact.CreateCalculator(); byte[] d = _pubKeyInfo.GetDerEncoded(); - calc.Stream.Write(d, 0, d.Length); - calc.Stream.Flush(); - Platform.Dispose(calc.Stream); + + IStreamCalculator<IBlockResult> calc = fact.CreateCalculator(); + using (var stream = calc.Stream) + { + stream.Write(d, 0, d.Length); + } this._publicKeyMAC = new PKMacValue( (AlgorithmIdentifier)fact.AlgorithmDetails, |