116 {
118 Span<byte> span = Span<byte>.Empty;
119 try
120 {
123 {
125 }
128 using IncrementalHash incrementalHash = IncrementalHash.CreateHash(
_hashAlgorithmName);
129 Span<byte> destination2 = span3.Slice(0,
_hLen);
130 Span<byte> destination3 = span3.Slice(span3.Length -
source.Length);
131 Span<byte> span4 = span3.Slice(
_hLen, span3.Length -
_hLen - 1 - destination3.Length);
132 Span<byte> span5 = span3.Slice(
_hLen + span4.Length, 1);
133 if (!incrementalHash.TryGetHashAndReset(destination2, out var bytesWritten) || bytesWritten !=
_hLen)
134 {
135 throw new CryptographicException();
136 }
137 span4.Clear();
138 span5[0] = 1;
139 source.CopyTo(destination3);
140 RandomNumberGenerator.Fill(span2);
142 span =
new Span<byte>(
array, 0, span3.Length);
143 Mgf1(incrementalHash, span2, span);
145 Span<byte> span6 = stackalloc
byte[
_hLen];
146 Mgf1(incrementalHash, span3, span6);
149 }
150 catch (Exception ex) when (!(ex is CryptographicException))
151 {
152 throw new CryptographicException();
153 }
154 finally
155 {
157 {
158 CryptographicOperations.ZeroMemory(span);
160 }
161 }
162 }
static string Format(string resourceFormat, object p1)
static string Cryptography_Encryption_MessageTooLong
static void Return(byte[] array, int clearSize=-1)
static byte[] Rent(int minimumLength)
void Mgf1(IncrementalHash hasher, ReadOnlySpan< byte > mgfSeed, Span< byte > mask)
static void Xor(Span< byte > a, ReadOnlySpan< byte > b)
readonly HashAlgorithmName _hashAlgorithmName