Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ EncryptOrDecrypt() [2/3]

unsafe byte[] System.Security.Cryptography.RSAImplementation.RSACng.EncryptOrDecrypt ( SafeNCryptKeyHandle key,
ReadOnlySpan< byte > input,
global::Interop::NCrypt::AsymmetricPaddingMode paddingMode,
void * paddingInfo,
bool encrypt )
inlineprivate

Definition at line 301 of file RSAImplementation.cs.

302 {
303 int num = KeySize / 8;
304 byte[] array = new byte[num];
305 int bytesNeeded = 0;
306 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.ErrorCode.ERROR_SUCCESS;
307 for (int i = 0; i <= 1; i++)
308 {
310 if (errorCode != global::Interop.NCrypt.ErrorCode.STATUS_UNSUCCESSFUL)
311 {
312 break;
313 }
314 }
315 if (errorCode == global::Interop.NCrypt.ErrorCode.NTE_BUFFER_TOO_SMALL)
316 {
317 CryptographicOperations.ZeroMemory(array);
318 array = new byte[bytesNeeded];
319 for (int j = 0; j <= 1; j++)
320 {
322 if (errorCode != global::Interop.NCrypt.ErrorCode.STATUS_UNSUCCESSFUL)
323 {
324 break;
325 }
326 }
327 }
328 if (errorCode != 0)
329 {
330 throw errorCode.ToCryptographicException();
331 }
332 if (bytesNeeded != array.Length)
333 {
334 byte[] array2 = array.AsSpan(0, bytesNeeded).ToArray();
335 CryptographicOperations.ZeroMemory(array);
336 array = array2;
337 }
338 return array;
339 }
unsafe byte[] EncryptOrDecrypt(byte[] data, RSAEncryptionPadding padding, bool encrypt)

References System.array, System.Security.Cryptography.RSAImplementation.RSACng.EncryptOrDecrypt(), System.input, System.key, System.Security.Cryptography.AsymmetricAlgorithm.KeySize, and System.Security.Cryptography.CryptographicOperations.ZeroMemory().