public static byte[] ExportCspBlob(SafeKeyHandleImpl symKeyHandle, SafeKeyHandleImpl keyExchangeHandle, int blobType) { uint exportedKeyLength = 0; if (!CryptoApi.CryptExportKey(symKeyHandle, keyExchangeHandle, (uint)blobType, 0, null, ref exportedKeyLength)) { throw CreateWin32Error(); } var exportedKeyBytes = new byte[exportedKeyLength]; if (!CryptoApi.CryptExportKey(symKeyHandle, keyExchangeHandle, (uint)blobType, 0, exportedKeyBytes, ref exportedKeyLength)) { throw CreateWin32Error(); } return(exportedKeyBytes); }