public static WpcPacket ParsePacket(string recvStr) { List <WpcEntry> o = WpcEntry.ParseDataEntry(recvStr); WpcEntry e; try { e = WpcEntry.FindEntry(o, "PACK"); if (e != null) { byte[] hash = Secure.HashSHA1(e.Data); Pack pack = null; pack = Pack.CreateFromBuf(new Buf(e.Data)); e = WpcEntry.FindEntry(o, "HASH"); if (e != null) { byte[] hash2 = e.Data; if (Util.CompareByte(hash, hash2)) { e = WpcEntry.FindEntry(o, "CERT"); if (e != null) { Cert cert; try { cert = new Cert(e.Data); } catch { return(null); } e = WpcEntry.FindEntry(o, "SIGN"); if (e != null) { byte[] sign = e.Data; if (cert.RsaPublicKey.VerifyData(hash2, sign)) { return(new WpcPacket(pack, hash2, cert, sign)); } } } else { return(new WpcPacket(pack, hash2)); } } } } } catch (OverflowException) { return(null); } return(null); }
private WpcPacket(Pack pack, byte[] hash) : this(pack, hash, null, null) { }
public static string GeneratePacket(Pack pack) { return(GeneratePacket(pack, null, null)); }
public void SetResponse(Pack pack, Cert cert, Rsa key) { responsePack = pack; responseCert = cert; responseKey = key; }