203 {
205 byte[] iV = cipher.IV;
206 int encodedLength =
source.GetEncodedLength();
208 int num = cipher.KeySize / 8;
209 int iterationCount = pbeParameters.IterationCount;
210 HashAlgorithmName hashAlgorithm = pbeParameters.HashAlgorithm;
212 if (!isPkcs12)
213 {
214 array = ((passwordBytes.Length == 0 && password.Length > 0) ?
new byte[uTF.
GetByteCount(password)] : ((passwordBytes.Length != 0) ?
new byte[passwordBytes.
Length] :
Array.
Empty<byte>()));
215 }
216 fixed (byte* ptr3 = array2)
217 {
218 fixed (
byte* ptr2 =
array)
219 {
220 byte[] array3;
221 if (isPkcs12)
222 {
223 array3 = new byte[num];
227 }
228 else
229 {
230 if (passwordBytes.
Length > 0)
231 {
233 }
234 else if (password.
Length > 0)
235 {
238 {
239 throw new CryptographicException();
240 }
241 }
242 using (Rfc2898DeriveBytes rfc2898DeriveBytes =
new Rfc2898DeriveBytes(
array, salt.
ToArray(), iterationCount, hashAlgorithm))
243 {
244 array3 = rfc2898DeriveBytes.GetBytes(num);
245 }
246 iV.CopyTo(ivDest);
247 }
248 fixed (byte* ptr = array3)
249 {
250 CryptographicOperations.ZeroMemory(
array);
251 using ICryptoTransform cryptoTransform = cipher.CreateEncryptor(array3, iV);
252 int num2 = cipher.BlockSize / 8;
253 int num3 = encodedLength % num2;
254 int num4 = encodedLength - num3;
255 try
256 {
257 if (!
source.TryEncode(array2, out var _))
258 {
259 throw new CryptographicException();
260 }
261 int num5 = 0;
262 if (num4 != 0)
263 {
264 num5 = cryptoTransform.TransformBlock(array2, 0, num4,
destination, 0);
265 }
266 byte[] array4 = cryptoTransform.TransformFinalBlock(array2, num5, num3);
268 return num5 + array4.Length;
269 }
270 finally
271 {
273 }
274 }
275 }
276 }
277 }
static void Return(byte[] array, int clearSize=-1)
static byte[] Rent(int minimumLength)
static void DeriveCipherKey(ReadOnlySpan< char > password, HashAlgorithmName hashAlgorithm, int iterationCount, ReadOnlySpan< byte > salt, Span< byte > destination)
static void DeriveIV(ReadOnlySpan< char > password, HashAlgorithmName hashAlgorithm, int iterationCount, ReadOnlySpan< byte > salt, Span< byte > destination)
virtual byte[] GetBytes(char[] chars)
virtual int GetByteCount(char[] chars)
void CopyTo(Span< T > destination)