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

◆ EncryptKey()

static void Internal.NativeCrypto.CapiHelper.EncryptKey ( SafeKeyHandle safeKeyHandle,
byte[] pbKey,
int cbKey,
bool foep,
[NotNull] ref byte[] pbEncryptedKey )
inlinestaticpackage

Definition at line 943 of file CapiHelper.cs.

944 {
945 VerifyValidHandle(safeKeyHandle);
946 int dwFlags = (foep ? 64 : 0);
947 int pdwDataLen = cbKey;
948 if (!global::Interop.Advapi32.CryptEncrypt(safeKeyHandle, SafeHashHandle.InvalidHandle, Final: true, dwFlags, null, ref pdwDataLen, pdwDataLen))
949 {
950 throw GetErrorCode().ToCryptographicException();
951 }
952 pbEncryptedKey = new byte[pdwDataLen];
953 Buffer.BlockCopy(pbKey, 0, pbEncryptedKey, 0, cbKey);
954 if (!global::Interop.Advapi32.CryptEncrypt(safeKeyHandle, SafeHashHandle.InvalidHandle, Final: true, dwFlags, pbEncryptedKey, ref cbKey, pdwDataLen))
955 {
956 throw GetErrorCode().ToCryptographicException();
957 }
958 Array.Reverse(pbEncryptedKey);
959 }
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.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.Encrypt().