68 {
69 for (
int i = 0;
i <= 1;
i++)
70 {
71 int pcbResult;
72 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptSignHash(keyHandle, pPaddingInfo, hash, hash.
Length, signature, signature.
Length, out pcbResult, paddingMode);
73 switch (errorCode)
74 {
75 case global::Interop.NCrypt.ErrorCode.ERROR_SUCCESS:
76 bytesWritten = pcbResult;
77 return true;
78 case global::Interop.NCrypt.ErrorCode.NTE_BUFFER_TOO_SMALL:
79 bytesWritten = 0;
80 return false;
81 default:
82 throw errorCode.ToCryptographicException();
83 case global::Interop.NCrypt.ErrorCode.STATUS_UNSUCCESSFUL:
84 break;
85 }
86 }
87 throw global::Interop.NCrypt.ErrorCode.STATUS_UNSUCCESSFUL.ToCryptographicException();
88 }