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

◆ DecryptKey()

static void Internal.NativeCrypto.CapiHelper.DecryptKey ( SafeKeyHandle safeKeyHandle,
byte[] encryptedData,
int encryptedDataLength,
bool fOAEP,
out byte[] decryptedData )
inlinestaticpackage

Definition at line 914 of file CapiHelper.cs.

915 {
916 VerifyValidHandle(safeKeyHandle);
917 byte[] array = new byte[encryptedDataLength];
918 Buffer.BlockCopy(encryptedData, 0, array, 0, encryptedDataLength);
920 int num = (fOAEP ? 64 : 0);
921 int pdwDataLen = encryptedDataLength;
922 if (!global::Interop.Advapi32.CryptDecrypt(safeKeyHandle, SafeHashHandle.InvalidHandle, Final: true, num, array, ref pdwDataLen))
923 {
924 int errorCode = GetErrorCode();
925 if ((num & 0x40) == 64)
926 {
927 switch (errorCode)
928 {
929 case -2146893815:
930 throw new CryptographicException("Cryptography_OAEP_XPPlus_Only");
931 default:
932 throw new CryptographicException("Cryptography_OAEPDecoding");
933 case -2146893821:
934 break;
935 }
936 }
937 throw errorCode.ToCryptographicException();
938 }
939 decryptedData = new byte[pdwDataLen];
940 Buffer.BlockCopy(array, 0, decryptedData, 0, pdwDataLen);
941 }
static void VerifyValidHandle(SafeHandleZeroOrMinusOneIsInvalid handle)
static void Reverse(Array array)
Definition Array.cs:2207
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102

References System.array, System.Buffer.BlockCopy(), Internal.NativeCrypto.CapiHelper.GetErrorCode(), System.Security.Cryptography.SafeHashHandle.InvalidHandle, System.Array.Reverse(), and Internal.NativeCrypto.CapiHelper.VerifyValidHandle().

Referenced by System.Security.Cryptography.RSACryptoServiceProvider.Decrypt().