internal static unsafe SafeHandle CryptDecodeObjectToMemory(CryptDecodeObjectStructType lpszStructType, byte[] pbEncoded) { fixed(byte *pbEncodedPointer = pbEncoded) { return(CryptDecodeObjectToMemory(lpszStructType, (IntPtr)pbEncodedPointer, pbEncoded.Length)); } }
internal static SafeHandle CryptDecodeObjectToMemory(CryptDecodeObjectStructType lpszStructType, byte[] pbEncoded) { unsafe { fixed (byte* pbEncodedPointer = pbEncoded) { return CryptDecodeObjectToMemory(lpszStructType, (IntPtr)pbEncodedPointer, pbEncoded.Length); } } }
private static byte[] DecodeKeyBlob(CryptDecodeObjectStructType lpszStructType, byte[] encodedKeyValue) { int cbDecoded = 0; if (!Interop.crypt32.CryptDecodeObject(CertEncodingType.All, lpszStructType, encodedKeyValue, encodedKeyValue.Length, CryptDecodeObjectFlags.None, null, ref cbDecoded)) throw new CryptographicException(Marshal.GetLastWin32Error()); byte[] keyBlob = new byte[cbDecoded]; if (!Interop.crypt32.CryptDecodeObject(CertEncodingType.All, lpszStructType, encodedKeyValue, encodedKeyValue.Length, CryptDecodeObjectFlags.None, keyBlob, ref cbDecoded)) throw new CryptographicException(Marshal.GetLastWin32Error()); return keyBlob; }
internal static unsafe byte[] CryptEncodeObjectToByteArray(CryptDecodeObjectStructType lpszStructType, void* decoded) { int cb = 0; if (!CryptEncodeObject(MsgEncodingType.All, lpszStructType, decoded, null, ref cb)) throw Marshal.GetLastWin32Error().ToCryptographicException(); byte[] encoded = new byte[cb]; if (!CryptEncodeObject(MsgEncodingType.All, lpszStructType, decoded, encoded, ref cb)) throw Marshal.GetLastWin32Error().ToCryptographicException(); return encoded.Resize(cb); }
internal static SafeHandle CryptDecodeObjectToMemory(CryptDecodeObjectStructType lpszStructType, IntPtr pbEncoded, int cbEncoded) { int cbRequired = 0; unsafe { if (!CryptDecodeObject(MsgEncodingType.All, (IntPtr)lpszStructType, pbEncoded, cbEncoded, 0, null, ref cbRequired)) throw Marshal.GetLastWin32Error().ToCryptographicException(); SafeHandle sh = SafeHeapAllocHandle.Alloc(cbRequired); if (!CryptDecodeObject(MsgEncodingType.All, (IntPtr)lpszStructType, pbEncoded, cbEncoded, 0, (void*)sh.DangerousGetHandle(), ref cbRequired)) throw Marshal.GetLastWin32Error().ToCryptographicException(); return sh; } }
public static unsafe bool DecodeObjectNoThrow <TState, TResult>( this ReadOnlySpan <byte> encoded, CryptDecodeObjectStructType lpszStructType, TState state, DecodedObjectReceiver <TState, TResult> receiver, out TResult?result) { int cb = 0; if (!Interop.crypt32.CryptDecodeObjectPointer( Interop.Crypt32.CertEncodingType.All, lpszStructType, encoded, Interop.Crypt32.CryptDecodeObjectFlags.None, null, ref cb)) { result = default; return(false); } const int MaxStackAllocSize = 256; Span <byte> decoded = stackalloc byte[MaxStackAllocSize]; if ((uint)cb > MaxStackAllocSize) { decoded = new byte[cb]; } fixed(byte *pDecoded = decoded) { if (!Interop.crypt32.CryptDecodeObjectPointer( Interop.Crypt32.CertEncodingType.All, lpszStructType, encoded, Interop.Crypt32.CryptDecodeObjectFlags.None, pDecoded, ref cb)) { result = default; return(false); } result = receiver(pDecoded, cb, state); } return(true); }
public static void DecodeObject(this byte[] encoded, CryptDecodeObjectStructType lpszStructType, DecodedObjectReceiver receiver) { unsafe { int cb = 0; if (!Interop.crypt32.CryptDecodeObjectPointer(CertEncodingType.All, lpszStructType, encoded, encoded.Length, CryptDecodeObjectFlags.None, null, ref cb)) throw Marshal.GetLastWin32Error().ToCryptographicException(); byte* decoded = stackalloc byte[cb]; if (!Interop.crypt32.CryptDecodeObjectPointer(CertEncodingType.All, lpszStructType, encoded, encoded.Length, CryptDecodeObjectFlags.None, (byte*)decoded, ref cb)) throw Marshal.GetLastWin32Error().ToCryptographicException(); receiver(decoded); } }
public static TResult DecodeObject <TResult>( this byte[] encoded, CryptDecodeObjectStructType lpszStructType, DecodedObjectReceiver <TResult> receiver) { unsafe { int cb = 0; if (!Interop.crypt32.CryptDecodeObjectPointer( Interop.Crypt32.CertEncodingType.All, lpszStructType, encoded, encoded.Length, Interop.Crypt32.CryptDecodeObjectFlags.None, null, ref cb)) { throw Marshal.GetLastPInvokeError().ToCryptographicException(); } int MaxStackAllocSize = 256; Span <byte> decoded = stackalloc byte[MaxStackAllocSize]; if ((uint)cb > MaxStackAllocSize) { decoded = new byte[cb]; } fixed(byte *pDecoded = decoded) { if (!Interop.crypt32.CryptDecodeObjectPointer( Interop.Crypt32.CertEncodingType.All, lpszStructType, encoded, encoded.Length, Interop.Crypt32.CryptDecodeObjectFlags.None, pDecoded, ref cb)) { throw Marshal.GetLastPInvokeError().ToCryptographicException(); } return(receiver(pDecoded, cb)); } } }
private static byte[] DecodeKeyBlob(CryptDecodeObjectStructType lpszStructType, byte[] encodedKeyValue) { int cbDecoded = 0; if (!Interop.crypt32.CryptDecodeObject(CertEncodingType.All, lpszStructType, encodedKeyValue, encodedKeyValue.Length, CryptDecodeObjectFlags.None, null, ref cbDecoded)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } byte[] keyBlob = new byte[cbDecoded]; if (!Interop.crypt32.CryptDecodeObject(CertEncodingType.All, lpszStructType, encodedKeyValue, encodedKeyValue.Length, CryptDecodeObjectFlags.None, keyBlob, ref cbDecoded)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } return(keyBlob); }
internal static unsafe byte[] CryptEncodeObjectToByteArray(CryptDecodeObjectStructType lpszStructType, void *decoded) { int cb = 0; if (!CryptEncodeObject(MsgEncodingType.All, lpszStructType, decoded, null, ref cb)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } byte[] encoded = new byte[cb]; if (!CryptEncodeObject(MsgEncodingType.All, lpszStructType, decoded, encoded, ref cb)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } return(encoded.Resize(cb)); }
public static unsafe byte[] EncodeObject(CryptDecodeObjectStructType lpszStructType, void *decoded) { int cb = 0; if (!Interop.crypt32.CryptEncodeObject(CertEncodingType.All, lpszStructType, decoded, null, ref cb)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } byte[] encoded = new byte[cb]; if (!Interop.crypt32.CryptEncodeObject(CertEncodingType.All, lpszStructType, decoded, encoded, ref cb)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } return(encoded); }
internal static unsafe SafeHandle CryptDecodeObjectToMemory(CryptDecodeObjectStructType lpszStructType, IntPtr pbEncoded, int cbEncoded) { int cbRequired = 0; if (!CryptDecodeObject(MsgEncodingType.All, (IntPtr)lpszStructType, pbEncoded, cbEncoded, 0, null, ref cbRequired)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } SafeHandle sh = SafeHeapAllocHandle.Alloc(cbRequired); if (!CryptDecodeObject(MsgEncodingType.All, (IntPtr)lpszStructType, pbEncoded, cbEncoded, 0, (void *)sh.DangerousGetHandle(), ref cbRequired)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } return(sh); }
public static void DecodeObject(this byte[] encoded, CryptDecodeObjectStructType lpszStructType, DecodedObjectReceiver receiver) { unsafe { int cb = 0; if (!Interop.crypt32.CryptDecodeObjectPointer(CertEncodingType.All, lpszStructType, encoded, encoded.Length, CryptDecodeObjectFlags.None, null, ref cb)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } byte *decoded = stackalloc byte[cb]; if (!Interop.crypt32.CryptDecodeObjectPointer(CertEncodingType.All, lpszStructType, encoded, encoded.Length, CryptDecodeObjectFlags.None, (byte *)decoded, ref cb)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } receiver(decoded); } }
public static bool DecodeObjectNoThrow(this byte[] encoded, CryptDecodeObjectStructType lpszStructType, DecodedObjectReceiver receiver) { unsafe { int cb = 0; if (!Interop.crypt32.CryptDecodeObjectPointer(CertEncodingType.All, lpszStructType, encoded, encoded.Length, CryptDecodeObjectFlags.None, null, ref cb)) { return(false); } byte *decoded = stackalloc byte[cb]; if (!Interop.crypt32.CryptDecodeObjectPointer(CertEncodingType.All, lpszStructType, encoded, encoded.Length, CryptDecodeObjectFlags.None, (byte *)decoded, ref cb)) { return(false); } receiver(decoded); } return(true); }
internal static unsafe bool CryptDecodeObject(CryptDecodeObjectStructType lpszStructType, IntPtr pbEncoded, int cbEncoded, void* pvStructInfo, ref int pcbStructInfo) { return CryptDecodeObject(MsgEncodingType.All, (IntPtr)lpszStructType, pbEncoded, cbEncoded, 0, pvStructInfo, ref pcbStructInfo); }
public static unsafe bool CryptEncodeObject(CertEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, void *pvStructInfo, byte[]?pbEncoded, ref int pcbEncoded) { return(CryptEncodeObject(dwCertEncodingType, (IntPtr)lpszStructType, pvStructInfo, pbEncoded, ref pcbEncoded)); }
public static unsafe bool CryptDecodeObjectPointer(CertEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, byte[] pbEncoded, int cbEncoded, CryptDecodeObjectFlags dwFlags, void *pvStructInfo, ref int pcbStructInfo) { return(CryptDecodeObjectPointer(dwCertEncodingType, (IntPtr)lpszStructType, pbEncoded, cbEncoded, dwFlags, pvStructInfo, ref pcbStructInfo)); }
public static bool CryptDecodeObject(Interop.Crypt32.CertEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, byte[] pbEncoded, int cbEncoded, Interop.Crypt32.CryptDecodeObjectFlags dwFlags, byte[]?pvStructInfo, ref int pcbStructInfo) { return(Interop.Crypt32.CryptDecodeObject(dwCertEncodingType, (IntPtr)lpszStructType, pbEncoded, cbEncoded, dwFlags, pvStructInfo, ref pcbStructInfo)); }
public static unsafe byte[] EncodeObject(CryptDecodeObjectStructType lpszStructType, void* decoded) { int cb = 0; if (!Interop.crypt32.CryptEncodeObject(CertEncodingType.All, lpszStructType, decoded, null, ref cb)) throw new CryptographicException(Marshal.GetLastWin32Error()); byte[] encoded = new byte[cb]; if (!Interop.crypt32.CryptEncodeObject(CertEncodingType.All, lpszStructType, decoded, encoded, ref cb)) throw new CryptographicException(Marshal.GetLastWin32Error()); return encoded; }
public static unsafe bool CryptEncodeObject(CertEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, void* pvStructInfo, byte[] pbEncoded, ref int pcbEncoded) { return CryptEncodeObject(dwCertEncodingType, (IntPtr)lpszStructType, pvStructInfo, pbEncoded, ref pcbEncoded); }
public static unsafe bool CryptDecodeObjectPointer(CertEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, byte[] pbEncoded, int cbEncoded, CryptDecodeObjectFlags dwFlags, void* pvStructInfo, ref int pcbStructInfo) { return CryptDecodeObjectPointer(dwCertEncodingType, (IntPtr)lpszStructType, pbEncoded, cbEncoded, dwFlags, pvStructInfo, ref pcbStructInfo); }
public static unsafe bool CryptDecodeObjectPointer(Interop.Crypt32.CertEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, ReadOnlySpan <byte> encoded, Interop.Crypt32.CryptDecodeObjectFlags dwFlags, void *pvStructInfo, ref int pcbStructInfo) { fixed(byte *pEncoded = encoded) { return(Interop.Crypt32.CryptDecodeObjectPointer(dwCertEncodingType, (IntPtr)lpszStructType, pEncoded, encoded.Length, dwFlags, pvStructInfo, ref pcbStructInfo)); } }
internal static unsafe bool CryptDecodeObject(CryptDecodeObjectStructType lpszStructType, IntPtr pbEncoded, int cbEncoded, void *pvStructInfo, ref int pcbStructInfo) { return(CryptDecodeObject(MsgEncodingType.All, (IntPtr)lpszStructType, pbEncoded, cbEncoded, 0, pvStructInfo, ref pcbStructInfo)); }
public static bool DecodeObjectNoThrow(this byte[] encoded, CryptDecodeObjectStructType lpszStructType, DecodedObjectReceiver receiver) { unsafe { int cb = 0; if (!Interop.crypt32.CryptDecodeObjectPointer(CertEncodingType.All, lpszStructType, encoded, encoded.Length, CryptDecodeObjectFlags.None, null, ref cb)) return false; byte* decoded = stackalloc byte[cb]; if (!Interop.crypt32.CryptDecodeObjectPointer(CertEncodingType.All, lpszStructType, encoded, encoded.Length, CryptDecodeObjectFlags.None, (byte*)decoded, ref cb)) return false; receiver(decoded); } return true; }
internal static unsafe bool CryptEncodeObject(MsgEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, void *pvStructInfo, byte[]?pbEncoded, ref int pcbEncoded) { return(CryptEncodeObject(dwCertEncodingType, (nint)lpszStructType, pvStructInfo, pbEncoded, ref pcbEncoded)); }