4 using System
.Runtime
.CompilerServices
;
5 using System
.Runtime
.InteropServices
;
6 using System
.Diagnostics
.CodeAnalysis
;
8 namespace Microsoft
.Runtime
.Hosting
{
11 /// The methods here are designed to aid in transition from the v2 StrongName APIs on mscoree.dll to the
12 /// v4 metahost APIs (which are in-proc SxS aware).
14 internal static class StrongNameHelpers
{
17 private static int ts_LastStrongNameHR
;
19 [System
.Security
.SecurityCritical
]
21 private static IClrStrongName s_StrongName
;
23 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
24 private static IClrStrongName StrongName
{
25 [System
.Security
.SecurityCritical
]
27 if (s_StrongName
== null) {
28 s_StrongName
= (IClrStrongName
)RuntimeEnvironment
.GetRuntimeInterfaceAsObject(
29 new Guid("B79B0ACD-F5CD-409b-B5A5-A16244610B92"),
30 new Guid("9FD93CCF-3280-4391-B3A9-96E1CDE77C8D"));
36 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
37 private static IClrStrongNameUsingIntPtr StrongNameUsingIntPtr
{
38 [System
.Security
.SecurityCritical
]
40 return (IClrStrongNameUsingIntPtr
)StrongName
;
44 [System
.Security
.SecurityCritical
]
45 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
46 public static int StrongNameErrorInfo() {
47 return ts_LastStrongNameHR
;
50 [System
.Security
.SecurityCritical
]
51 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
52 [SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId
= "Microsoft.Runtime.Hosting.IClrStrongNameUsingIntPtr.StrongNameFreeBuffer(System.IntPtr)", Justification
= "StrongNameFreeBuffer returns void but the new runtime wrappers return an HRESULT.")]
53 public static void StrongNameFreeBuffer(IntPtr pbMemory
) {
54 StrongNameUsingIntPtr
.StrongNameFreeBuffer(pbMemory
);
57 [System
.Security
.SecurityCritical
]
58 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
59 public static bool StrongNameGetPublicKey(string pwzKeyContainer
, IntPtr pbKeyBlob
, int cbKeyBlob
, out IntPtr ppbPublicKeyBlob
, out int pcbPublicKeyBlob
) {
60 int hr
= StrongNameUsingIntPtr
.StrongNameGetPublicKey(pwzKeyContainer
, pbKeyBlob
, cbKeyBlob
, out ppbPublicKeyBlob
, out pcbPublicKeyBlob
);
63 ts_LastStrongNameHR
= hr
;
64 ppbPublicKeyBlob
= IntPtr
.Zero
;
72 [System
.Security
.SecurityCritical
]
73 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
74 public static bool StrongNameKeyDelete(string pwzKeyContainer
) {
75 int hr
= StrongName
.StrongNameKeyDelete(pwzKeyContainer
);
78 ts_LastStrongNameHR
= hr
;
84 [System
.Security
.SecurityCritical
]
85 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
86 public static bool StrongNameKeyGen(string pwzKeyContainer
, int dwFlags
, out IntPtr ppbKeyBlob
, out int pcbKeyBlob
) {
87 int hr
= StrongName
.StrongNameKeyGen(pwzKeyContainer
, dwFlags
, out ppbKeyBlob
, out pcbKeyBlob
);
90 ts_LastStrongNameHR
= hr
;
91 ppbKeyBlob
= IntPtr
.Zero
;
98 [System
.Security
.SecurityCritical
]
99 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
100 public static bool StrongNameKeyInstall(string pwzKeyContainer
, IntPtr pbKeyBlob
, int cbKeyBlob
) {
101 int hr
= StrongNameUsingIntPtr
.StrongNameKeyInstall(pwzKeyContainer
, pbKeyBlob
, cbKeyBlob
);
104 ts_LastStrongNameHR
= hr
;
110 [System
.Security
.SecurityCritical
]
111 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
112 public static bool StrongNameSignatureGeneration(string pwzFilePath
, string pwzKeyContainer
, IntPtr pbKeyBlob
, int cbKeyBlob
) {
113 IntPtr ppbSignatureBlob
= IntPtr
.Zero
;
114 int cbSignatureBlob
= 0;
115 return StrongNameSignatureGeneration(pwzFilePath
, pwzKeyContainer
, pbKeyBlob
, cbKeyBlob
, ref ppbSignatureBlob
, out cbSignatureBlob
);
119 [System
.Security
.SecurityCritical
]
120 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
121 public static bool StrongNameSignatureGeneration(string pwzFilePath
, string pwzKeyContainer
, IntPtr pbKeyBlob
, int cbKeyBlob
, ref IntPtr ppbSignatureBlob
, out int pcbSignatureBlob
) {
122 int hr
= StrongNameUsingIntPtr
.StrongNameSignatureGeneration(pwzFilePath
, pwzKeyContainer
, pbKeyBlob
, cbKeyBlob
, ppbSignatureBlob
, out pcbSignatureBlob
);
125 ts_LastStrongNameHR
= hr
;
126 pcbSignatureBlob
= 0;
132 [System
.Security
.SecurityCritical
]
133 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
134 public static bool StrongNameSignatureSize(IntPtr pbPublicKeyBlob
, int cbPublicKeyBlob
, out int pcbSize
) {
135 int hr
= StrongNameUsingIntPtr
.StrongNameSignatureSize(pbPublicKeyBlob
, cbPublicKeyBlob
, out pcbSize
);
138 ts_LastStrongNameHR
= hr
;
145 [System
.Security
.SecurityCritical
]
146 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
147 public static bool StrongNameSignatureVerification(string pwzFilePath
, int dwInFlags
, out int pdwOutFlags
) {
148 int hr
= StrongName
.StrongNameSignatureVerification(pwzFilePath
, dwInFlags
, out pdwOutFlags
);
151 ts_LastStrongNameHR
= hr
;
158 [System
.Security
.SecurityCritical
]
159 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
160 public static bool StrongNameSignatureVerificationEx(string pwzFilePath
, bool fForceVerification
, out bool pfWasVerified
) {
161 int hr
= StrongName
.StrongNameSignatureVerificationEx(pwzFilePath
, fForceVerification
, out pfWasVerified
);
164 ts_LastStrongNameHR
= hr
;
165 pfWasVerified
= false;
171 [System
.Security
.SecurityCritical
]
172 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
173 public static bool StrongNameTokenFromPublicKey(IntPtr pbPublicKeyBlob
, int cbPublicKeyBlob
, out IntPtr ppbStrongNameToken
, out int pcbStrongNameToken
) {
174 int hr
= StrongNameUsingIntPtr
.StrongNameTokenFromPublicKey(pbPublicKeyBlob
, cbPublicKeyBlob
, out ppbStrongNameToken
, out pcbStrongNameToken
);
177 ts_LastStrongNameHR
= hr
;
178 ppbStrongNameToken
= IntPtr
.Zero
;
179 pcbStrongNameToken
= 0;
185 [System
.Security
.SecurityCritical
]
186 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
187 public static bool StrongNameSignatureSize(byte[] bPublicKeyBlob
, int cbPublicKeyBlob
, out int pcbSize
) {
188 int hr
= StrongName
.StrongNameSignatureSize(bPublicKeyBlob
, cbPublicKeyBlob
, out pcbSize
);
191 ts_LastStrongNameHR
= hr
;
197 [System
.Security
.SecurityCritical
]
198 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
199 public static bool StrongNameTokenFromPublicKey(byte[] bPublicKeyBlob
, int cbPublicKeyBlob
, out IntPtr ppbStrongNameToken
, out int pcbStrongNameToken
) {
200 int hr
= StrongName
.StrongNameTokenFromPublicKey(bPublicKeyBlob
, cbPublicKeyBlob
, out ppbStrongNameToken
, out pcbStrongNameToken
);
203 ts_LastStrongNameHR
= hr
;
204 ppbStrongNameToken
= IntPtr
.Zero
;
205 pcbStrongNameToken
= 0;
211 [System
.Security
.SecurityCritical
]
212 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
213 public static bool StrongNameGetPublicKey(string pwzKeyContainer
, byte[] bKeyBlob
, int cbKeyBlob
, out IntPtr ppbPublicKeyBlob
, out int pcbPublicKeyBlob
) {
214 int hr
= StrongName
.StrongNameGetPublicKey(pwzKeyContainer
, bKeyBlob
, cbKeyBlob
, out ppbPublicKeyBlob
, out pcbPublicKeyBlob
);
217 ts_LastStrongNameHR
= hr
;
218 ppbPublicKeyBlob
= IntPtr
.Zero
;
219 pcbPublicKeyBlob
= 0;
225 [System
.Security
.SecurityCritical
]
226 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
227 public static bool StrongNameKeyInstall(string pwzKeyContainer
, byte[] bKeyBlob
, int cbKeyBlob
) {
228 int hr
= StrongName
.StrongNameKeyInstall(pwzKeyContainer
, bKeyBlob
, cbKeyBlob
);
231 ts_LastStrongNameHR
= hr
;
237 [System
.Security
.SecurityCritical
]
238 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
239 public static bool StrongNameSignatureGeneration(string pwzFilePath
, string pwzKeyContainer
, byte[] bKeyBlob
, int cbKeyBlob
) {
240 IntPtr ppbSignatureBlob
= IntPtr
.Zero
;
241 int cbSignatureBlob
= 0;
242 return StrongNameSignatureGeneration(pwzFilePath
, pwzKeyContainer
, bKeyBlob
, cbKeyBlob
, ref ppbSignatureBlob
, out cbSignatureBlob
);
245 [System
.Security
.SecurityCritical
]
246 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification
= "Microsoft: This file is included in a lot of projects some of which only use a subset of the functions.")]
247 public static bool StrongNameSignatureGeneration(string pwzFilePath
, string pwzKeyContainer
, byte[] bKeyBlob
, int cbKeyBlob
, ref IntPtr ppbSignatureBlob
, out int pcbSignatureBlob
) {
248 int hr
= StrongName
.StrongNameSignatureGeneration(pwzFilePath
, pwzKeyContainer
, bKeyBlob
, cbKeyBlob
, ppbSignatureBlob
, out pcbSignatureBlob
);
251 ts_LastStrongNameHR
= hr
;
252 pcbSignatureBlob
= 0;
261 /// This is a managed wrapper for the IClrStrongName interface defined in metahost.idl
262 /// This uses IntPtrs in some places where you'd normally expect a byte[] in order to
263 /// be compatible with callers who wrote their PInvoke signatures that way.
264 /// Ideally we'd probably just simplify all such callers to using byte[] and remove this
265 /// version of the interface.
267 [System
.Security
.SecurityCritical
]
268 [ComImport
, ComConversionLoss
, InterfaceType(ComInterfaceType
.InterfaceIsIUnknown
), Guid("9FD93CCF-3280-4391-B3A9-96E1CDE77C8D")]
269 internal interface IClrStrongNameUsingIntPtr
{
270 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
272 int GetHashFromAssemblyFile(
273 [In
, MarshalAs(UnmanagedType
.LPStr
)] string pszFilePath
,
274 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
275 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
276 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
277 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
279 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
281 int GetHashFromAssemblyFileW(
282 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
283 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
284 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
285 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
286 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
288 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
292 [In
, MarshalAs(UnmanagedType
.U4
)] int cchBlob
,
293 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
294 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 4)] byte[] pbHash
,
295 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
296 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
298 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
301 [In
, MarshalAs(UnmanagedType
.LPStr
)] string pszFilePath
,
302 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
303 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
304 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
305 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
307 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
309 int GetHashFromFileW(
310 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
311 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
312 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
313 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
314 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
316 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
318 int GetHashFromHandle(
320 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
321 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
322 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
323 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
325 [return: MarshalAs(UnmanagedType
.U4
)]
326 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
328 int StrongNameCompareAssemblies(
329 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzAssembly1
,
330 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzAssembly2
,
331 [MarshalAs(UnmanagedType
.U4
)] out int dwResult
);
333 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
335 int StrongNameFreeBuffer(
336 [In
] IntPtr pbMemory
);
338 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
340 int StrongNameGetBlob(
341 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
342 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 2)] byte[] pbBlob
,
343 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int pcbBlob
);
345 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
347 int StrongNameGetBlobFromImage(
349 [In
, MarshalAs(UnmanagedType
.U4
)] int dwLength
,
350 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbBlob
,
351 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int pcbBlob
);
353 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
355 int StrongNameGetPublicKey(
356 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
357 [In
] IntPtr pbKeyBlob
,
358 [In
, MarshalAs(UnmanagedType
.U4
)] int cbKeyBlob
,
359 out IntPtr ppbPublicKeyBlob
,
360 [MarshalAs(UnmanagedType
.U4
)] out int pcbPublicKeyBlob
);
362 [return: MarshalAs(UnmanagedType
.U4
)]
363 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
365 int StrongNameHashSize(
366 [In
, MarshalAs(UnmanagedType
.U4
)] int ulHashAlg
,
367 [MarshalAs(UnmanagedType
.U4
)] out int cbSize
);
369 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
371 int StrongNameKeyDelete(
372 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
);
374 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
376 int StrongNameKeyGen(
377 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
378 [In
, MarshalAs(UnmanagedType
.U4
)] int dwFlags
,
379 out IntPtr ppbKeyBlob
,
380 [MarshalAs(UnmanagedType
.U4
)] out int pcbKeyBlob
);
382 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
384 int StrongNameKeyGenEx(
385 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
386 [In
, MarshalAs(UnmanagedType
.U4
)] int dwFlags
,
387 [In
, MarshalAs(UnmanagedType
.U4
)] int dwKeySize
,
388 out IntPtr ppbKeyBlob
,
389 [MarshalAs(UnmanagedType
.U4
)] out int pcbKeyBlob
);
391 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
393 int StrongNameKeyInstall(
394 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
395 [In
] IntPtr pbKeyBlob
,
396 [In
, MarshalAs(UnmanagedType
.U4
)] int cbKeyBlob
);
398 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
400 int StrongNameSignatureGeneration(
401 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
402 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
403 [In
] IntPtr pbKeyBlob
,
404 [In
, MarshalAs(UnmanagedType
.U4
)] int cbKeyBlob
,
405 [In
, Out
] IntPtr ppbSignatureBlob
,
406 [MarshalAs(UnmanagedType
.U4
)] out int pcbSignatureBlob
);
408 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
410 int StrongNameSignatureGenerationEx(
411 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string wszFilePath
,
412 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string wszKeyContainer
,
413 [In
] IntPtr pbKeyBlob
,
414 [In
, MarshalAs(UnmanagedType
.U4
)] int cbKeyBlob
,
415 [In
, Out
] IntPtr ppbSignatureBlob
,
416 [MarshalAs(UnmanagedType
.U4
)] out int pcbSignatureBlob
,
417 [In
, MarshalAs(UnmanagedType
.U4
)] int dwFlags
);
419 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
421 int StrongNameSignatureSize(
422 [In
] IntPtr pbPublicKeyBlob
,
423 [In
, MarshalAs(UnmanagedType
.U4
)] int cbPublicKeyBlob
,
424 [MarshalAs(UnmanagedType
.U4
)] out int pcbSize
);
426 [return: MarshalAs(UnmanagedType
.U4
)]
427 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
429 int StrongNameSignatureVerification(
430 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
431 [In
, MarshalAs(UnmanagedType
.U4
)] int dwInFlags
,
432 [MarshalAs(UnmanagedType
.U4
)] out int dwOutFlags
);
434 [return: MarshalAs(UnmanagedType
.U4
)]
435 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
437 int StrongNameSignatureVerificationEx(
438 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
439 [In
, MarshalAs(UnmanagedType
.I1
)] bool fForceVerification
,
440 [MarshalAs(UnmanagedType
.I1
)] out bool fWasVerified
);
442 [return: MarshalAs(UnmanagedType
.U4
)]
443 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
445 int StrongNameSignatureVerificationFromImage(
447 [In
, MarshalAs(UnmanagedType
.U4
)] int dwLength
,
448 [In
, MarshalAs(UnmanagedType
.U4
)] int dwInFlags
,
449 [MarshalAs(UnmanagedType
.U4
)] out int dwOutFlags
);
451 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
453 int StrongNameTokenFromAssembly(
454 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
455 out IntPtr ppbStrongNameToken
,
456 [MarshalAs(UnmanagedType
.U4
)] out int pcbStrongNameToken
);
458 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
460 int StrongNameTokenFromAssemblyEx(
461 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
462 out IntPtr ppbStrongNameToken
,
463 [MarshalAs(UnmanagedType
.U4
)] out int pcbStrongNameToken
,
464 out IntPtr ppbPublicKeyBlob
,
465 [MarshalAs(UnmanagedType
.U4
)] out int pcbPublicKeyBlob
);
467 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
469 int StrongNameTokenFromPublicKey(
470 [In
] IntPtr pbPublicKeyBlob
,
471 [In
, MarshalAs(UnmanagedType
.U4
)] int cbPublicKeyBlob
,
472 out IntPtr ppbStrongNameToken
,
473 [MarshalAs(UnmanagedType
.U4
)] out int pcbStrongNameToken
);
477 /// This is a managed wrapper for the IClrStrongName interface defined in metahost.idl
478 /// This is very similar to the standard RCWs provided in
479 /// ndp/fx/src/hosting/interop/microsoft/runtime/hosting/interop, but we don't want to
480 /// reference that assembly (part of the SDK only, not .NET redist). Also, our version
481 /// is designed specifically for easy migration from the old mscoree APIs, for example
482 /// all APIs return HResults rather than throw exceptions.
484 [System
.Security
.SecurityCritical
]
485 [ComImport
, ComConversionLoss
, InterfaceType(ComInterfaceType
.InterfaceIsIUnknown
), Guid("9FD93CCF-3280-4391-B3A9-96E1CDE77C8D")]
486 internal interface IClrStrongName
{
487 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
489 int GetHashFromAssemblyFile(
490 [In
, MarshalAs(UnmanagedType
.LPStr
)] string pszFilePath
,
491 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
492 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
493 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
494 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
496 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
498 int GetHashFromAssemblyFileW(
499 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
500 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
501 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
502 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
503 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
505 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
509 [In
, MarshalAs(UnmanagedType
.U4
)] int cchBlob
,
510 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
511 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 4)] byte[] pbHash
,
512 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
513 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
515 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
518 [In
, MarshalAs(UnmanagedType
.LPStr
)] string pszFilePath
,
519 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
520 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
521 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
522 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
524 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
526 int GetHashFromFileW(
527 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
528 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
529 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
530 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
531 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
533 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
535 int GetHashFromHandle(
537 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int piHashAlg
,
538 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbHash
,
539 [In
, MarshalAs(UnmanagedType
.U4
)] int cchHash
,
540 [MarshalAs(UnmanagedType
.U4
)] out int pchHash
);
542 [return: MarshalAs(UnmanagedType
.U4
)]
543 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
545 int StrongNameCompareAssemblies(
546 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzAssembly1
,
547 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzAssembly2
,
548 [MarshalAs(UnmanagedType
.U4
)] out int dwResult
);
550 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
552 int StrongNameFreeBuffer(
553 [In
] IntPtr pbMemory
);
555 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
557 int StrongNameGetBlob(
558 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
559 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 2)] byte[] pbBlob
,
560 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int pcbBlob
);
562 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
564 int StrongNameGetBlobFromImage(
566 [In
, MarshalAs(UnmanagedType
.U4
)] int dwLength
,
567 [Out
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbBlob
,
568 [In
, Out
, MarshalAs(UnmanagedType
.U4
)] ref int pcbBlob
);
570 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
572 int StrongNameGetPublicKey(
573 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
574 [In
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 2)] byte[] pbKeyBlob
,
575 [In
, MarshalAs(UnmanagedType
.U4
)] int cbKeyBlob
,
576 out IntPtr ppbPublicKeyBlob
,
577 [MarshalAs(UnmanagedType
.U4
)] out int pcbPublicKeyBlob
);
579 [return: MarshalAs(UnmanagedType
.U4
)]
580 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
582 int StrongNameHashSize(
583 [In
, MarshalAs(UnmanagedType
.U4
)] int ulHashAlg
,
584 [MarshalAs(UnmanagedType
.U4
)] out int cbSize
);
586 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
588 int StrongNameKeyDelete(
589 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
);
591 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
593 int StrongNameKeyGen(
594 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
595 [In
, MarshalAs(UnmanagedType
.U4
)] int dwFlags
,
596 out IntPtr ppbKeyBlob
,
597 [MarshalAs(UnmanagedType
.U4
)] out int pcbKeyBlob
);
599 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
601 int StrongNameKeyGenEx(
602 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
603 [In
, MarshalAs(UnmanagedType
.U4
)] int dwFlags
,
604 [In
, MarshalAs(UnmanagedType
.U4
)] int dwKeySize
,
605 out IntPtr ppbKeyBlob
,
606 [MarshalAs(UnmanagedType
.U4
)] out int pcbKeyBlob
);
608 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
610 int StrongNameKeyInstall(
611 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
612 [In
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 2)] byte[] pbKeyBlob
,
613 [In
, MarshalAs(UnmanagedType
.U4
)] int cbKeyBlob
);
615 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
617 int StrongNameSignatureGeneration(
618 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
619 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzKeyContainer
,
620 [In
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbKeyBlob
,
621 [In
, MarshalAs(UnmanagedType
.U4
)] int cbKeyBlob
,
622 [In
, Out
] IntPtr ppbSignatureBlob
,
623 [MarshalAs(UnmanagedType
.U4
)] out int pcbSignatureBlob
);
625 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
627 int StrongNameSignatureGenerationEx(
628 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string wszFilePath
,
629 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string wszKeyContainer
,
630 [In
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 3)] byte[] pbKeyBlob
,
631 [In
, MarshalAs(UnmanagedType
.U4
)] int cbKeyBlob
,
632 [In
, Out
] IntPtr ppbSignatureBlob
,
633 [MarshalAs(UnmanagedType
.U4
)] out int pcbSignatureBlob
,
634 [In
, MarshalAs(UnmanagedType
.U4
)] int dwFlags
);
636 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
638 int StrongNameSignatureSize(
639 [In
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 1)] byte[] pbPublicKeyBlob
,
640 [In
, MarshalAs(UnmanagedType
.U4
)] int cbPublicKeyBlob
,
641 [MarshalAs(UnmanagedType
.U4
)] out int pcbSize
);
643 [return: MarshalAs(UnmanagedType
.U4
)]
644 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
646 int StrongNameSignatureVerification(
647 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
648 [In
, MarshalAs(UnmanagedType
.U4
)] int dwInFlags
,
649 [MarshalAs(UnmanagedType
.U4
)] out int dwOutFlags
);
651 [return: MarshalAs(UnmanagedType
.U4
)]
652 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
654 int StrongNameSignatureVerificationEx(
655 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
656 [In
, MarshalAs(UnmanagedType
.I1
)] bool fForceVerification
,
657 [MarshalAs(UnmanagedType
.I1
)] out bool fWasVerified
);
659 [return: MarshalAs(UnmanagedType
.U4
)]
660 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
662 int StrongNameSignatureVerificationFromImage(
664 [In
, MarshalAs(UnmanagedType
.U4
)] int dwLength
,
665 [In
, MarshalAs(UnmanagedType
.U4
)] int dwInFlags
,
666 [MarshalAs(UnmanagedType
.U4
)] out int dwOutFlags
);
668 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
670 int StrongNameTokenFromAssembly(
671 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
672 out IntPtr ppbStrongNameToken
,
673 [MarshalAs(UnmanagedType
.U4
)] out int pcbStrongNameToken
);
675 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
677 int StrongNameTokenFromAssemblyEx(
678 [In
, MarshalAs(UnmanagedType
.LPWStr
)] string pwzFilePath
,
679 out IntPtr ppbStrongNameToken
,
680 [MarshalAs(UnmanagedType
.U4
)] out int pcbStrongNameToken
,
681 out IntPtr ppbPublicKeyBlob
,
682 [MarshalAs(UnmanagedType
.U4
)] out int pcbPublicKeyBlob
);
684 [MethodImpl(MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
686 int StrongNameTokenFromPublicKey(
687 [In
, MarshalAs(UnmanagedType
.LPArray
, SizeParamIndex
= 1)] byte[] pbPublicKeyBlob
,
688 [In
, MarshalAs(UnmanagedType
.U4
)] int cbPublicKeyBlob
,
689 out IntPtr ppbStrongNameToken
,
690 [MarshalAs(UnmanagedType
.U4
)] out int pcbStrongNameToken
);