我正在使用这个小类,它返回一个字节数组中的 pfx 文件。
服务器端:
byte[] serverCertificatebyte;
var date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
serverCertificatebyte = Certificate.CreateSelfSignCertificatePfx("CN=RustBuster" + RandomString(5),
date,
date.AddDays(7));
Run Code Online (Sandbox Code Playgroud)
然后我将其发送给客户端(长度:1654):
tcpClient.GetStream().Write(serverCertificatebyte , 0, serverCertificatebyte .Length);
Run Code Online (Sandbox Code Playgroud)
一旦客户端读取它,我想将它转换为证书类:(这里长度也是1654)
我尝试做一个新的 X509Certificate2(data); 我在下面得到了错误。这适用于服务器端。怎么了?
我还尝试了 new X509Certificate2(data, string.Empty); 并得到同样的错误
错误 System.Security.Cryptography.CryptographicException:无法解码证书。---> System.Security.Cryptography.CryptographicException:输入数据无法编码为有效证书。---> System.ArgumentOutOfRangeException:不能为负数。
参数名称:长度
在 System.String.Substring (Int32 startIndex, Int32 length) [0x00000] in :0
在 Mono.Security.X509.X509Certificate.PEM (System.String 类型,System.Byte[] 数据)[0x00000] 中:0
在 Mono.Security.X509.X509Certificate..ctor (System.Byte[] data) [0x00000] 中:0
我在发送密钥时遇到了一些麻烦。似乎当我想发送密钥时它不起作用。
我正在考虑发送诸如 T 之类的字母字符以从示例中进行聊天,但是如果我将它写入枚举,则无论何时使用它们都不会发生任何事情。有任何想法吗?
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
/// <summary>
/// Virtual Keys
/// </summary>
public enum VirtualKeyStates : int
{
VK_LBUTTON = 0x01,
VK_RBUTTON = 0x02,
VK_CANCEL = 0x03,
VK_MBUTTON = 0x04,
//
VK_XBUTTON1 = 0x05,
VK_XBUTTON2 = 0x06,
//
VK_BACK = 0x08,
VK_TAB = 0x09,
//
VK_CLEAR …Run Code Online (Sandbox Code Playgroud)