ホーム › Security.Cryptography › NCryptStreamOpenToUnprotectEx
NCryptStreamOpenToUnprotectEx
関数拡張情報を用いてストリーム復号用ハンドルを開く。
シグネチャ
// ncrypt.dll
#include <windows.h>
HRESULT NCryptStreamOpenToUnprotectEx(
NCRYPT_PROTECT_STREAM_INFO_EX* pStreamInfo,
DWORD dwFlags,
HWND hWnd, // optional
NCRYPT_STREAM_HANDLE* phStream
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pStreamInfo | NCRYPT_PROTECT_STREAM_INFO_EX* | in | NCRYPT_PROTECT_STREAM_INFO_EX へのポインターです。 |
| dwFlags | DWORD | in | NCRYPT_SILENT_FLAG のみがサポートされます。 |
| hWnd | HWND | inoptional | 表示されるユーザーインターフェイスの親として使用するウィンドウハンドルです。 |
| phStream | NCRYPT_STREAM_HANDLE* | out | ストリームハンドルへのポインターを受け取ります。 |
戻り値の型: HRESULT
公式ドキュメント
暗号化に使用したものと同じ保護記述子に対して、大量のデータを復号するために使用できるストリームオブジェクトを開きます。(NCryptStreamOpenToUnprotectEx)
戻り値
関数の成功または失敗を示すステータスコードを返します。 返される可能性のあるコードには、以下のものが含まれますが、これらに限定されません。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ncrypt.dll
#include <windows.h>
HRESULT NCryptStreamOpenToUnprotectEx(
NCRYPT_PROTECT_STREAM_INFO_EX* pStreamInfo,
DWORD dwFlags,
HWND hWnd, // optional
NCRYPT_STREAM_HANDLE* phStream
);[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptStreamOpenToUnprotectEx(
IntPtr pStreamInfo, // NCRYPT_PROTECT_STREAM_INFO_EX*
uint dwFlags, // DWORD
IntPtr hWnd, // HWND optional
IntPtr phStream // NCRYPT_STREAM_HANDLE* out
);<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptStreamOpenToUnprotectEx(
pStreamInfo As IntPtr, ' NCRYPT_PROTECT_STREAM_INFO_EX*
dwFlags As UInteger, ' DWORD
hWnd As IntPtr, ' HWND optional
phStream As IntPtr ' NCRYPT_STREAM_HANDLE* out
) As Integer
End Function' pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX*
' dwFlags : DWORD
' hWnd : HWND optional
' phStream : NCRYPT_STREAM_HANDLE* out
Declare PtrSafe Function NCryptStreamOpenToUnprotectEx Lib "ncrypt" ( _
ByVal pStreamInfo As LongPtr, _
ByVal dwFlags As Long, _
ByVal hWnd As LongPtr, _
ByVal phStream As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NCryptStreamOpenToUnprotectEx = ctypes.windll.ncrypt.NCryptStreamOpenToUnprotectEx
NCryptStreamOpenToUnprotectEx.restype = ctypes.c_int
NCryptStreamOpenToUnprotectEx.argtypes = [
ctypes.c_void_p, # pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX*
wintypes.DWORD, # dwFlags : DWORD
wintypes.HANDLE, # hWnd : HWND optional
ctypes.c_void_p, # phStream : NCRYPT_STREAM_HANDLE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ncrypt.dll')
NCryptStreamOpenToUnprotectEx = Fiddle::Function.new(
lib['NCryptStreamOpenToUnprotectEx'],
[
Fiddle::TYPE_VOIDP, # pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX*
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # hWnd : HWND optional
Fiddle::TYPE_VOIDP, # phStream : NCRYPT_STREAM_HANDLE* out
],
Fiddle::TYPE_INT)#[link(name = "ncrypt")]
extern "system" {
fn NCryptStreamOpenToUnprotectEx(
pStreamInfo: *mut NCRYPT_PROTECT_STREAM_INFO_EX, // NCRYPT_PROTECT_STREAM_INFO_EX*
dwFlags: u32, // DWORD
hWnd: *mut core::ffi::c_void, // HWND optional
phStream: *mut *mut core::ffi::c_void // NCRYPT_STREAM_HANDLE* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ncrypt.dll")]
public static extern int NCryptStreamOpenToUnprotectEx(IntPtr pStreamInfo, uint dwFlags, IntPtr hWnd, IntPtr phStream);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptStreamOpenToUnprotectEx' -Namespace Win32 -PassThru
# $api::NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream)#uselib "ncrypt.dll"
#func global NCryptStreamOpenToUnprotectEx "NCryptStreamOpenToUnprotectEx" sptr, sptr, sptr, sptr
; NCryptStreamOpenToUnprotectEx varptr(pStreamInfo), dwFlags, hWnd, phStream ; 戻り値は stat
; pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> "sptr"
; dwFlags : DWORD -> "sptr"
; hWnd : HWND optional -> "sptr"
; phStream : NCRYPT_STREAM_HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ncrypt.dll" #cfunc global NCryptStreamOpenToUnprotectEx "NCryptStreamOpenToUnprotectEx" var, int, sptr, sptr ; res = NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream) ; pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> "var" ; dwFlags : DWORD -> "int" ; hWnd : HWND optional -> "sptr" ; phStream : NCRYPT_STREAM_HANDLE* out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ncrypt.dll" #cfunc global NCryptStreamOpenToUnprotectEx "NCryptStreamOpenToUnprotectEx" sptr, int, sptr, sptr ; res = NCryptStreamOpenToUnprotectEx(varptr(pStreamInfo), dwFlags, hWnd, phStream) ; pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> "sptr" ; dwFlags : DWORD -> "int" ; hWnd : HWND optional -> "sptr" ; phStream : NCRYPT_STREAM_HANDLE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT NCryptStreamOpenToUnprotectEx(NCRYPT_PROTECT_STREAM_INFO_EX* pStreamInfo, DWORD dwFlags, HWND hWnd, NCRYPT_STREAM_HANDLE* phStream) #uselib "ncrypt.dll" #cfunc global NCryptStreamOpenToUnprotectEx "NCryptStreamOpenToUnprotectEx" var, int, intptr, intptr ; res = NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream) ; pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> "var" ; dwFlags : DWORD -> "int" ; hWnd : HWND optional -> "intptr" ; phStream : NCRYPT_STREAM_HANDLE* out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT NCryptStreamOpenToUnprotectEx(NCRYPT_PROTECT_STREAM_INFO_EX* pStreamInfo, DWORD dwFlags, HWND hWnd, NCRYPT_STREAM_HANDLE* phStream) #uselib "ncrypt.dll" #cfunc global NCryptStreamOpenToUnprotectEx "NCryptStreamOpenToUnprotectEx" intptr, int, intptr, intptr ; res = NCryptStreamOpenToUnprotectEx(varptr(pStreamInfo), dwFlags, hWnd, phStream) ; pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> "intptr" ; dwFlags : DWORD -> "int" ; hWnd : HWND optional -> "intptr" ; phStream : NCRYPT_STREAM_HANDLE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
procNCryptStreamOpenToUnprotectEx = ncrypt.NewProc("NCryptStreamOpenToUnprotectEx")
)
// pStreamInfo (NCRYPT_PROTECT_STREAM_INFO_EX*), dwFlags (DWORD), hWnd (HWND optional), phStream (NCRYPT_STREAM_HANDLE* out)
r1, _, err := procNCryptStreamOpenToUnprotectEx.Call(
uintptr(pStreamInfo),
uintptr(dwFlags),
uintptr(hWnd),
uintptr(phStream),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction NCryptStreamOpenToUnprotectEx(
pStreamInfo: Pointer; // NCRYPT_PROTECT_STREAM_INFO_EX*
dwFlags: DWORD; // DWORD
hWnd: THandle; // HWND optional
phStream: Pointer // NCRYPT_STREAM_HANDLE* out
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptStreamOpenToUnprotectEx';result := DllCall("ncrypt\NCryptStreamOpenToUnprotectEx"
, "Ptr", pStreamInfo ; NCRYPT_PROTECT_STREAM_INFO_EX*
, "UInt", dwFlags ; DWORD
, "Ptr", hWnd ; HWND optional
, "Ptr", phStream ; NCRYPT_STREAM_HANDLE* out
, "Int") ; return: HRESULT●NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream) = DLL("ncrypt.dll", "int NCryptStreamOpenToUnprotectEx(void*, dword, void*, void*)")
# 呼び出し: NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream)
# pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> "void*"
# dwFlags : DWORD -> "dword"
# hWnd : HWND optional -> "void*"
# phStream : NCRYPT_STREAM_HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ncrypt" fn NCryptStreamOpenToUnprotectEx(
pStreamInfo: [*c]NCRYPT_PROTECT_STREAM_INFO_EX, // NCRYPT_PROTECT_STREAM_INFO_EX*
dwFlags: u32, // DWORD
hWnd: ?*anyopaque, // HWND optional
phStream: ?*anyopaque // NCRYPT_STREAM_HANDLE* out
) callconv(std.os.windows.WINAPI) i32;proc NCryptStreamOpenToUnprotectEx(
pStreamInfo: ptr NCRYPT_PROTECT_STREAM_INFO_EX, # NCRYPT_PROTECT_STREAM_INFO_EX*
dwFlags: uint32, # DWORD
hWnd: pointer, # HWND optional
phStream: pointer # NCRYPT_STREAM_HANDLE* out
): int32 {.importc: "NCryptStreamOpenToUnprotectEx", stdcall, dynlib: "ncrypt.dll".}pragma(lib, "ncrypt");
extern(Windows)
int NCryptStreamOpenToUnprotectEx(
NCRYPT_PROTECT_STREAM_INFO_EX* pStreamInfo, // NCRYPT_PROTECT_STREAM_INFO_EX*
uint dwFlags, // DWORD
void* hWnd, // HWND optional
void* phStream // NCRYPT_STREAM_HANDLE* out
);ccall((:NCryptStreamOpenToUnprotectEx, "ncrypt.dll"), stdcall, Int32,
(Ptr{NCRYPT_PROTECT_STREAM_INFO_EX}, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
pStreamInfo, dwFlags, hWnd, phStream)
# pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> Ptr{NCRYPT_PROTECT_STREAM_INFO_EX}
# dwFlags : DWORD -> UInt32
# hWnd : HWND optional -> Ptr{Cvoid}
# phStream : NCRYPT_STREAM_HANDLE* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t NCryptStreamOpenToUnprotectEx(
void* pStreamInfo,
uint32_t dwFlags,
void* hWnd,
void* phStream);
]]
local ncrypt = ffi.load("ncrypt")
-- ncrypt.NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream)
-- pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX*
-- dwFlags : DWORD
-- hWnd : HWND optional
-- phStream : NCRYPT_STREAM_HANDLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ncrypt.dll');
const NCryptStreamOpenToUnprotectEx = lib.func('__stdcall', 'NCryptStreamOpenToUnprotectEx', 'int32_t', ['void *', 'uint32_t', 'void *', 'void *']);
// NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream)
// pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> 'void *'
// dwFlags : DWORD -> 'uint32_t'
// hWnd : HWND optional -> 'void *'
// phStream : NCRYPT_STREAM_HANDLE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ncrypt.dll", {
NCryptStreamOpenToUnprotectEx: { parameters: ["pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream)
// pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> "pointer"
// dwFlags : DWORD -> "u32"
// hWnd : HWND optional -> "pointer"
// phStream : NCRYPT_STREAM_HANDLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t NCryptStreamOpenToUnprotectEx(
void* pStreamInfo,
uint32_t dwFlags,
void* hWnd,
void* phStream);
C, "ncrypt.dll");
// $ffi->NCryptStreamOpenToUnprotectEx(pStreamInfo, dwFlags, hWnd, phStream);
// pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX*
// dwFlags : DWORD
// hWnd : HWND optional
// phStream : NCRYPT_STREAM_HANDLE* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Ncrypt extends StdCallLibrary {
Ncrypt INSTANCE = Native.load("ncrypt", Ncrypt.class);
int NCryptStreamOpenToUnprotectEx(
Pointer pStreamInfo, // NCRYPT_PROTECT_STREAM_INFO_EX*
int dwFlags, // DWORD
Pointer hWnd, // HWND optional
Pointer phStream // NCRYPT_STREAM_HANDLE* out
);
}@[Link("ncrypt")]
lib Libncrypt
fun NCryptStreamOpenToUnprotectEx = NCryptStreamOpenToUnprotectEx(
pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX*, # NCRYPT_PROTECT_STREAM_INFO_EX*
dwFlags : UInt32, # DWORD
hWnd : Void*, # HWND optional
phStream : Void* # NCRYPT_STREAM_HANDLE* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NCryptStreamOpenToUnprotectExNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>);
typedef NCryptStreamOpenToUnprotectExDart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Void>);
final NCryptStreamOpenToUnprotectEx = DynamicLibrary.open('ncrypt.dll')
.lookupFunction<NCryptStreamOpenToUnprotectExNative, NCryptStreamOpenToUnprotectExDart>('NCryptStreamOpenToUnprotectEx');
// pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// hWnd : HWND optional -> Pointer<Void>
// phStream : NCRYPT_STREAM_HANDLE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NCryptStreamOpenToUnprotectEx(
pStreamInfo: Pointer; // NCRYPT_PROTECT_STREAM_INFO_EX*
dwFlags: DWORD; // DWORD
hWnd: THandle; // HWND optional
phStream: Pointer // NCRYPT_STREAM_HANDLE* out
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptStreamOpenToUnprotectEx';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NCryptStreamOpenToUnprotectEx"
c_NCryptStreamOpenToUnprotectEx :: Ptr () -> Word32 -> Ptr () -> Ptr () -> IO Int32
-- pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> Ptr ()
-- dwFlags : DWORD -> Word32
-- hWnd : HWND optional -> Ptr ()
-- phStream : NCRYPT_STREAM_HANDLE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ncryptstreamopentounprotectex =
foreign "NCryptStreamOpenToUnprotectEx"
((ptr void) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> (ptr void) *)
(* dwFlags : DWORD -> uint32_t *)
(* hWnd : HWND optional -> (ptr void) *)
(* phStream : NCRYPT_STREAM_HANDLE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ncrypt (t "ncrypt.dll"))
(cffi:use-foreign-library ncrypt)
(cffi:defcfun ("NCryptStreamOpenToUnprotectEx" ncrypt-stream-open-to-unprotect-ex :convention :stdcall) :int32
(p-stream-info :pointer) ; NCRYPT_PROTECT_STREAM_INFO_EX*
(dw-flags :uint32) ; DWORD
(h-wnd :pointer) ; HWND optional
(ph-stream :pointer)) ; NCRYPT_STREAM_HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NCryptStreamOpenToUnprotectEx = Win32::API::More->new('ncrypt',
'int NCryptStreamOpenToUnprotectEx(LPVOID pStreamInfo, DWORD dwFlags, HANDLE hWnd, HANDLE phStream)');
# my $ret = $NCryptStreamOpenToUnprotectEx->Call($pStreamInfo, $dwFlags, $hWnd, $phStream);
# pStreamInfo : NCRYPT_PROTECT_STREAM_INFO_EX* -> LPVOID
# dwFlags : DWORD -> DWORD
# hWnd : HWND optional -> HANDLE
# phStream : NCRYPT_STREAM_HANDLE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f NCryptStreamOpenToUnprotect — ストリーム形式で保護データを復号するためのハンドルを開く。