CryptoThrowHelper
using System;
using System.Runtime.Serialization;
using System.Security.Cryptography;
namespace Internal.Cryptography
{
internal static class CryptoThrowHelper
{
[Serializable]
private sealed class WindowsCryptographicException : CryptographicException
{
public WindowsCryptographicException(int hr, string message)
: base(message)
{
base.HResult = hr;
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.SetType(typeof(CryptographicException));
base.GetObjectData(info, context);
}
}
public static CryptographicException ToCryptographicException(this int hr)
{
string message = global::Interop.Kernel32.GetMessage(hr);
if (hr >= 0)
hr = ((hr & 65535) | -2147024896);
return new WindowsCryptographicException(hr, message);
}
}
}