From 4b68aeba5f86a3eb536e66114b99e241c254dc0b Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 6 Oct 2022 12:16:59 +0700 Subject: Refactor RSACoreEngine.ConvertOutput --- crypto/src/crypto/engines/RSACoreEngine.cs | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/crypto/src/crypto/engines/RSACoreEngine.cs b/crypto/src/crypto/engines/RSACoreEngine.cs index 5f6e98eea..bd3d62f7c 100644 --- a/crypto/src/crypto/engines/RSACoreEngine.cs +++ b/crypto/src/crypto/engines/RSACoreEngine.cs @@ -3,6 +3,7 @@ using System; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; using Org.BouncyCastle.Security; +using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Crypto.Engines { @@ -103,28 +104,13 @@ namespace Org.BouncyCastle.Crypto.Engines return input; } - public virtual byte[] ConvertOutput( - BigInteger result) + public virtual byte[] ConvertOutput(BigInteger result) { CheckInitialised(); - byte[] output = result.ToByteArrayUnsigned(); - - if (forEncryption) - { - int outSize = GetOutputBlockSize(); - - // TODO To avoid this, create version of BigInteger.ToByteArray that - // writes to an existing array - if (output.Length < outSize) // have ended up with less bytes than normal, lengthen - { - byte[] tmp = new byte[outSize]; - output.CopyTo(tmp, tmp.Length - output.Length); - output = tmp; - } - } - - return output; + return forEncryption + ? BigIntegers.AsUnsignedByteArray(GetOutputBlockSize(), result) + : BigIntegers.AsUnsignedByteArray(result); } public virtual BigInteger ProcessBlock( -- cgit 1.4.1